Saturday, November 7, 2009

page_load event firing twice in firefox with asp.net page or user control.

Technorati Tags: ,,

We are having a very large project in asp.net 3.5. During code review of project we have found that page_load event of one control is firing twice in the firefox browser. After doing some debugging i have found that it's due to one of the link button which is there in the control. I like to share you the same scenario with you all guys.

One of the developer from us has specified the link button click event  two times.  The first one in directly in the html with onclick  like following.



Code Snippet



  1. <form id="form1" runat="server">
  2.     <div>
  3.         <asp:LinkButton ID="lnkButton" runat="server" onclick="lnkButton_Click"></asp:LinkButton>
  4.     </div>
  5.     </form>




And another in the initialize event he has also attached the event handler for the click event like following.



Code Snippet



  1. protected override void OnInit(EventArgs e)
  2.         {
  3.             lnkButton.Click += new EventHandler(lnkButton_Click);    
  4.             base.OnInit(e);
  5.         }




So i have removed one of them from initialize event and now its calling page_load event only one time. This is also responsible for the failed to load ViewState error some time when you are adding controls dynamically.

Happy programming...

Shout it
Share:

2 comments:

  1. there are other things in aspx that also causes to fire page_load twice in firefox only.

    please refer this article for more details

    http://patelshailesh.com/index.php/page_load-event-fires-twice-with-firefox-only

    ReplyDelete

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews