ASP.NET User control initialization

N

Norman Kaye

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
 
V

Victor Garcia Aprea [MVP]

Hi Norman,
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
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top