ASP.NET User control initialization

Discussion in 'ASP .Net Web Controls' started by Norman Kaye, Jan 5, 2004.

  1. Norman Kaye

    Norman Kaye Guest

    Hi,

    I've replaced my #include page header with a user control. now I want
    to set the text on the buttons within the control depending upon
    session variables -
    I've tried using the Page_Load event in the user control's ascx.vb
    codebehind, but that never seems to execute, I've tried to access the
    user control from the main web page aspx.vb codebehind, by declaring
    the user control and calling a public method in the ascx.vb - I can't
    get that to work, so I've gone for a really simple solution - call
    vbscript directly within the page. At least this code executes, but
    does not change the button text.

    I have as follows:

    in the page:

    <% PgHeader.OnHdrPageLoad() %>
    <Hdr:Header id="PgHeader" name="PageHeader"
    runat="server></Hdr:Header>


    in the control:

    <script language="vb" runat="server>
    Sub OnHdrPageLoad()
    If Session("LoggedIn") = True Then
    button1.Text = "Log Out"
    Label1.Text = "User :" & Session("UserName") & " Logged In")
    Else
    button1.Text = "Log In"
    Label1.Text = ""
    End If
    End Sub


    How is a simple thing like this supposed to be done?
    Thanks in advance
     
    Norman Kaye, Jan 5, 2004
    #1
    1. Advertising

  2. Hi Norman,

    >>> I've tried using the Page_Load event in the user control's ascx.vb
    >>> codebehind, but that never seems to execute,

    This should work ok. Are you using "AutoEventWireup"? VS.NET likes to delete
    the event wiring code from time to time, so if you're using codebehind you
    may want to check if its there.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    "Norman Kaye" <> wrote in message
    news:...
    > Hi,
    >
    > I've replaced my #include page header with a user control. now I want
    > to set the text on the buttons within the control depending upon
    > session variables -
    > I've tried using the Page_Load event in the user control's ascx.vb
    > codebehind, but that never seems to execute, I've tried to access the
    > user control from the main web page aspx.vb codebehind, by declaring
    > the user control and calling a public method in the ascx.vb - I can't
    > get that to work, so I've gone for a really simple solution - call
    > vbscript directly within the page. At least this code executes, but
    > does not change the button text.
    >
    > I have as follows:
    >
    > in the page:
    >
    > <% PgHeader.OnHdrPageLoad() %>
    > <Hdr:Header id="PgHeader" name="PageHeader"
    > runat="server></Hdr:Header>
    >
    >
    > in the control:
    >
    > <script language="vb" runat="server>
    > Sub OnHdrPageLoad()
    > If Session("LoggedIn") = True Then
    > button1.Text = "Log Out"
    > Label1.Text = "User :" & Session("UserName") & " Logged In")
    > Else
    > button1.Text = "Log In"
    > Label1.Text = ""
    > End If
    > End Sub
    >
    >
    > How is a simple thing like this supposed to be done?
    > Thanks in advance
     
    Victor Garcia Aprea [MVP], Jan 5, 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. JKop
    Replies:
    10
    Views:
    950
  2. Matthias Kaeppler
    Replies:
    2
    Views:
    446
    Victor Bazarov
    Jul 18, 2005
  3. Replies:
    6
    Views:
    465
    Ron Natalie
    Dec 11, 2005
  4. toton
    Replies:
    5
    Views:
    935
    Victor Bazarov
    Sep 28, 2006
  5. satyajit
    Replies:
    2
    Views:
    2,758
    satyajit
    Aug 21, 2007
Loading...

Share This Page