Wednesday, March 21, 2012

passing variables from page to control

I have a simple index.aspx page that declares and sets a sectionID in the
Page_Load. The in a user control later on in the page, I read the sectionID
variable (in the control's Page_Load) to determine which panel to show. It
does not work
"Name 'sectionID' is not declared" is my error while compiling the user
control.
What am I doing wrong?
This is in my main page's Page_Load
Dim sectionID As String = "about"
--
This is in my user control's Page_Load
If sectionID = "about" Then
pnlAbout.Visible = True
ElseIf sectionID = "home" Then
pnlHome.Visible = True
End If
_____
DC GMake a public property or method on your control that accepts the value from
your page. Something like this:
Public Sub SetSection(Section as Integer)
'Now I have the value I need
End Sub
The from your page, call it like this to pass the value along:
MyControlName.SetSectionID(sectionID)
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"DC Gringo" <dcgringo@.visiontechnology.net> wrote in message
news:OHsJ5uBREHA.2876@.TK2MSFTNGP09.phx.gbl...
> I have a simple index.aspx page that declares and sets a sectionID in the
> Page_Load. The in a user control later on in the page, I read the
sectionID
> variable (in the control's Page_Load) to determine which panel to show.
It
> does not work
> "Name 'sectionID' is not declared" is my error while compiling the user
> control.
> What am I doing wrong?
>
> This is in my main page's Page_Load
> Dim sectionID As String = "about"
> --
>
> This is in my user control's Page_Load
> If sectionID = "about" Then
> pnlAbout.Visible = True
> ElseIf sectionID = "home" Then
> pnlHome.Visible = True
> End If
>
> _____
> DC G
>

0 comments:

Post a Comment