passing variables from page to control

D

DC Gringo

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
 
S

Steve C. Orr [MVP, MCSD]

Make 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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top