[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Page Load event does not fire in User Control?

Girish Bhatia

1/16/2003 7:21:00 PM

I have a User control called TopOfPage in which I have a
label. I have the following code in which when the page
loads, I would like to set the value of the lable to
either Login or Logoff depeneding on whether the cookie
was set or not.

public abstract class TopOfPage : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.LinkButton
lbLogin;

private void Page_Load(object sender,
System.EventArgs e)
{
// Put user code to initialize the page here
if (HttpContext.Current.Request.Cookies
["User"] == null)
{
lbLogin.Text = "Login";
}
else
{
lbLogin.Text = "Logoff";
}

}

This user control is used in every Web Forms page
(login.aspx, Register.aspx etc). When a web form page is
loaded that contains the TopofPage user control, the
Page_Load event of the user control does not fire. Is
there a reason why? Am I doing something wrong?

I tried to debug the code from VS.NET by stepping through
and setting a breakpoint at the Page_Load of the user
control, but even this does not work. Any ideas?
1 Answer

(Tommy)

1/21/2003 10:10:00 PM

0

On your web user control ASCX file, if the "AutoEventWireUp" property
is set to "False", then on your web user control code behind, you'll
have to explicitly handle the page load event.

Try to change

private void Page_Load(object sender, System.EventArgs e)

to

private void Page_Load(object sender, System.EventArgs e) Handles
MyBase.Load


Tommy,

"Girish Bhatia" <nospam.girish.bhatia@sogeti-usa.com> wrote in message news:<746b01c2bd8c$1298a560$cef82ecf@TK2MSFTNGXA08>...
> I have a User control called TopOfPage in which I have a
> label. I have the following code in which when the page
> loads, I would like to set the value of the lable to
> either Login or Logoff depeneding on whether the cookie
> was set or not.
>
> public abstract class TopOfPage : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.LinkButton
> lbLogin;
>
> private void Page_Load(object sender,
> System.EventArgs e)
> {
> // Put user code to initialize the page here
> if (HttpContext.Current.Request.Cookies
> ["User"] == null)
> {
> lbLogin.Text = "Login";
> }
> else
> {
> lbLogin.Text = "Logoff";
> }
>
> }
>
> This user control is used in every Web Forms page
> (login.aspx, Register.aspx etc). When a web form page is
> loaded that contains the TopofPage user control, the
> Page_Load event of the user control does not fire. Is
> there a reason why? Am I doing something wrong?
>
> I tried to debug the code from VS.NET by stepping through
> and setting a breakpoint at the Page_Load of the user
> control, but even this does not work. Any ideas?