passing variables from page to control

Discussion in 'ASP .Net' started by DC Gringo, May 27, 2004.

  1. DC Gringo

    DC Gringo Guest

    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
    DC Gringo, May 27, 2004
    #1
    1. Advertising

  2. 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)

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net




    "DC Gringo" <> wrote in message
    news:...
    > 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
    >
    >
    Steve C. Orr [MVP, MCSD], May 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    2
    Views:
    679
    darrel
    May 21, 2004
  2. Philip Poole
    Replies:
    3
    Views:
    531
    Jim Corey
    Sep 23, 2004
  3. =?Utf-8?B?RGFuIE5hc2g=?=

    passing variables to a user control

    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    530
    =?Utf-8?B?RGFuIE5hc2g=?=
    Oct 7, 2004
  4. Fernando Chilvarguer

    Passing variables from ASPX page to ASCX control

    Fernando Chilvarguer, Aug 31, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    11,476
    Fernando Chilvarguer
    Sep 1, 2006
  5. Replies:
    9
    Views:
    924
Loading...

Share This Page