Page Load event fires twice

G

Guest

Hi,

I have a BasePage class from which all other ASPX pages of the project is inherited. The BasePage class implements Page_Load event handler. All child pages have its AutoEventWireUp property set to false.

I have included the code used to create the BasePage and one of the child pages below.

// Class BasePage

public class BasePage : Page
{
// To be overriden by child web pages to intialize page on
// page load event
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}

protected void Page_Load(object sender, System.EventArgs e)
{
BuildMenu();
}

}
 
G

Guest

Please ignore the previous post of mine, it is incomplete. I have provided a complete description of my problem in this post.

----------------------------------------------------------------------------------------------------------------------------

I have a BasePage class from which all other ASPX pages of the project is inherited. The BasePage class implements Page_Load event handler. All child pages have its AutoEventWireUp property set to false.

I have included the code used to create the BasePage and one of the child pages below.

----------------------------------------------------------------------------------------------------------------------------
// BasePage class declaration begins here

public class BasePage : Page
{
// To be overriden by child web pages to intialize page on
// page load event
virtual protected void PageLoadEvent(object sender, System.EventArgs e)
{}

protected void Page_Load(object sender, System.EventArgs e)
{
BuildMenu();
}

private void BuildMenu()
{
//Includes code to construct popup menu dynamically
//...
//..
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}//end of BasePage class declaration
----------------------------------------------------------------------------------------------------------------------------
//ChildPage.aspx
//From HTML view
<%@ Page language="c#" Codebehind="ChildPage.aspx.cs" AutoEventWireup="false" Inherits="ChildPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>Home Page</TITLE>
<META content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<META content="C#" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<BODY leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout">
<FORM id="frmSearch" method="post" runat="server">
<TABLE>
<TR >
<TD align="center" colSpan="4><ASP:TEXTBOX id="txtKeyword" runat="server" Width="190px"></ASP:TEXTBOX></TD>
</TR>
<TR >
<TD align="center" colSpan="4"><ASP:BUTTON id="cmdOK" runat="server" Text="Search"></ASP:BUTTON>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

//From Code-behind file - ChildPage.aspx .cs

public class ChildPage: BasePage
{
protected System.Web.UI.WebControls.TextBox txtKeyword;
protected System.Web.UI.WebControls.Button cmdOK;

protected override void PageLoadEvent(object sender, System.EventArgs e)
{
//Displays logged on users details on the page
DisplayLogonInfo();
}
private void DisplayLogonInfo()
{
//Include code for displaying looged on user's information
//...
//...
}
private void cmdOK_Click(object sender, System.EventArgs e)
{
//Processes OK button click
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
}
#endregion
}//End of ChildPage class declaration

----------------------------------------------------------------------------------------------------------------------------
Could anyone tell me how to prevent the Page_Load event from getting fired twice?

Thanks in advance.

Regards,
Magdelin
 

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