By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

Page Load event fires twice

P: n/a
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();
}

}

Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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



Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.