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.btnSearch.Click +=
new System.EventHandler(this.btnSearch_Click);
this.grdList.ItemDataBound +=
new System.Web.UI.WebControls.DataGridItemEventHandler(this.grdList_ItemDataBound);
this.Load +=
new System.EventHandler(this.Page_Load);
Check to see if you "AutoEventWireup" set to true. If this is a control, check the parent control/page also. Even if the control itself is set to false, but the parent is set to true, it seems to fire anyway.
We've been changing them from Page_Load to <Control>_Load in our usercontrols just for that reason.
Yes, you will need autopostback=true if you want the postback to occur immediately the event occurs in the UI.
If you are using autoeventwireup=true then make sure that you are not manually hooking up the event handlers in the code behind as well, e.g. cmdAddPanel3.Click += new ImageClickEventHandler(cmdAddPanel3_Click);
If you could post the entire web form and code behind file then I could test it out here and see if I get the same problem.
I'm having the same problem and in Visual Studio 2005 the event handlers in the code behind are hidden or non existant, I can't seem to find it how do I look it up. If how do I get them to show up.
Whenever I add a WARP Infragistics control and set the triggercontrolids property it changes the source code, so those infragistics users watch out, when you set that
I know this is an older topic but in case anyone encounters the same issue, I just wanted to share the solution to my particular situation for this problem:
I had pasted the following "Initializecomponent" code into my solution as part of some 3rd party code I had copied from the internet.
#region Web Form Designer generated codeoverride
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
The issue was the line beginning with "this.Load". Once I pulled that code out, everything worked fine.
ShimonSim
Member
54 Points
22 Posts
Load fires twice.
May 15, 2006 12:53 PM|LINK
I just noticed that after I migrated my project Load event started firing twice and even code in if(!IsPostBack) fires twice.
It seems to be that the reason is that asp.net 2.0 adds Page_Load automatically for Load event and since in 1.1 version there was line like:
this.Load+=new EventHandler(thi.Page_Load);
it is added second time.
For some reason in my case this line wasn't removed by "Convert to Web Application" command.
Just wanted to make sure that I have to do it myself and that this know bug.
Thank you,
Shimon.
mbund
Member
630 Points
126 Posts
Microsoft
Re: Load fires twice.
May 16, 2006 03:39 PM|LINK
Hi Shimon,
Can you tell me what function contains the line
this.Load+=new EventHandler(thi.Page_Load);
Also, is there any user-added code in that function?
Thanks!
ShimonSim
Member
54 Points
22 Posts
Re: Load fires twice.
May 16, 2006 05:14 PM|LINK
For a example like this
#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.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); this.grdList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grdList_ItemDataBound); this.Load += new System.EventHandler(this.Page_Load);}
#endregion
ashram99
Member
55 Points
11 Posts
Re: Load fires twice.
May 16, 2006 08:23 PM|LINK
We've been changing them from Page_Load to <Control>_Load in our usercontrols just for that reason.
-mkc
BGriffin_TPA
Member
489 Points
311 Posts
Re: Load fires twice.
Apr 21, 2007 06:32 PM|LINK
ashram99 :
I tried both AutoEventWireup=false (and true) and it made no change.
The page load fires twice on DDL's in an updatepanel. The autopostback=true
because I need to capture the selectedindexchanged event. Even tho in an
updatepanel the DDL causes a postback. if I setautopostback=false the event
is queued and eventually fires when I hit a button which causes a postback, but
that's too late to do what I need to do. Here is the HTML, if it will help.
<%--*** the add new panel/form --%> <asp:Panel ID="Panel3" runat="server" BackColor="PaleGoldenrod" Height="265px" Style="left: 256px; position: absolute; top: 352px; display:none;" EnableTheming="False" Width="270px" > <div style="border: 1px outset white; width: 250px; height: 245px; left: 8px; position: absolute; top: 8px;" align="left"> <asp:Label ID="lblInMarket" runat="server" EnableTheming="False" EnableViewState="False" Font-Bold="True" ForeColor="Black" Height="16px" Style="font-size: 8pt; left: 0.1in; color: black; font-family: Tahoma; position: absolute; top: 0.18in" Text="In Market:" Width="64px"></asp:Label> <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers=true runat="server"> <ContentTemplate> <asp:Label ID="lblSearchBy" runat="server" Font-Bold="True" ForeColor="Black" Height="16px" Style="font-size: 8pt; left: 0.08in; color: black; font-family: Tahoma; position: absolute; top: 0.47in; text-align: right" Text="Search By:" Width="64px"></asp:Label> <asp:Label ID="lblFor" runat="server" Font-Bold="True" ForeColor="Black" Height="16px" Style="font-size: 8pt; left: 0.41in; color: black; font-family: Tahoma; position: absolute; top: 0.75in; text-align: right" Text="For:" Width="32px"></asp:Label> <asp:Label ID="lblMessage" runat="server" BackColor="White" BorderColor="#00C000" Font-Bold="True" Style="left: 8px; position: absolute; top: 192px; text-align: center;" Text="Signals on new additions to your watch list (when they occur) are available within 24 hours." Width="232px" EnableTheming="False" EnableViewState="False" ForeColor="#C00000"></asp:Label> <asp:DropDownList ID="cmbMarket" runat="server" Style="left: 0.84in; position: absolute; top: 0.13in" TabIndex="1" Width="96px" EnableTheming="False" AutoPostBack="True"> </asp:DropDownList> <asp:DropDownList ID="cmbSearchBy" runat="server" Style="left: 0.84in; position: absolute; top: 0.42in" TabIndex="1" Width="96px" EnableTheming="False" AutoPostBack="True"> </asp:DropDownList> <asp:TextBox ID="txtSearchFor" runat="server" EnableTheming="False" Height="14px" MaxLength="25" Style="font-size: 13px; left: 0.84in; position: absolute; top: 0.71in" TabIndex="2" Width="144px"></asp:TextBox> <asp:TextBox ID="TxtCoName" runat="server" EnableTheming="False" Height="14px" MaxLength="35" ReadOnly="True" Style="font-size: 12px; left: 0.81in; position: absolute; top: 1.28in" TabIndex="-1" Width="136px" EnableViewState="False"></asp:TextBox> <asp:ImageButton ID="cmdSearch" runat="server" CausesValidation="False" EnableTheming="False" EnableViewState="False" Height="22px" ImageUrl="~/Images/Static/_Find.jpg" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('cmdSearch','','Images/Static/_FindOver.jpg',1)" Style="left: 80px; position: absolute; top: 96px" Width="90px" OnClick="cmdSearch_Click" /> <asp:ImageButton ID="cmdAddPanel3" runat="server" CausesValidation="False" EnableTheming="False" EnableViewState="False" Height="22px" ImageUrl="~/Images/Static/_AddNew.jpg" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('cmdAddNew','','Images/Static/_AddNewOver.jpg',1)" Style="left: 40px; position: absolute; top: 160px" Width="90px" OnClick="cmdAddPanel3_Click" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="cmbMarket" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="cmbSearchBy" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="cmdSearch" EventName="Click" /> </Triggers> </asp:UpdatePanel> <asp:ImageButton ID="cmdAddCancel" runat="server" EnableTheming="False" EnableViewState="False" Height="22px" ImageUrl="~/Images/Static/_AddNewCancel.jpg" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('cmdCancel','','Images/Static/_AddNewCancelOver.jpg',1)" Style="left: 144px; position: absolute; top: 160px" Width="90px" OnClick="cmdAddCancel_Click" CausesValidation="False" /> </div> </asp:Panel> <AjaxControlToolkit:ModalPopupExtender ID="ModalPopupExtender3" runat="server" BackgroundCssClass="modalBackground" TargetControlID="cmdAddnew" PopupControlID="Panel3"> </AjaxControlToolkit:ModalPopupExtender>Thanks for any help..
Jason Hill
Contributor
2019 Points
497 Posts
Re: Load fires twice.
Apr 23, 2007 08:42 PM|LINK
Yes, you will need autopostback=true if you want the postback to occur immediately the event occurs in the UI.
If you are using autoeventwireup=true then make sure that you are not manually hooking up the event handlers in the code behind as well, e.g. cmdAddPanel3.Click += new ImageClickEventHandler(cmdAddPanel3_Click);
If you could post the entire web form and code behind file then I could test it out here and see if I get the same problem.
DrSpeedo
Member
22 Points
15 Posts
Re: Load fires twice.
Apr 27, 2007 03:23 PM|LINK
lordofthexin...
Member
16 Points
24 Posts
Re: Load fires twice.
Oct 29, 2007 09:30 PM|LINK
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
lordofthexin...
Member
16 Points
24 Posts
Re: Load fires twice.
Oct 29, 2007 09:48 PM|LINK
Whenever I add a WARP Infragistics control and set the triggercontrolids property it changes the source code, so those infragistics users watch out, when you set that
Goalie35
Member
196 Points
194 Posts
Re: Load fires twice.
Mar 05, 2009 02:00 AM|LINK
I know this is an older topic but in case anyone encounters the same issue, I just wanted to share the solution to my particular situation for this problem:
I had pasted the following "Initializecomponent" code into my solution as part of some 3rd party code I had copied from the internet.
#region Web Form Designer generated codeoverride 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
The issue was the line beginning with "this.Load". Once I pulled that code out, everything worked fine.
-Goalie35