Amazon.com Widgets July 2008

WilliaBlog.Net

I dream in code

About the author

Robert Williams is an internet application developer for the Salem Web Network.
E-mail me Send mail
Code Project Associate Logo
Go Daddy Deal of the Week: 30% off your order at GoDaddy.com! Offer expires 11/6/12

Recent comments

Archive

Authors

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.


Page Load Event Fires Twice

If you have set a breakpoint in the page_load event of your web form and have found it fires twice, view source on the page and check for anything that uses a src="" attribute that is either empty or contains number sign (src="#"). If you find one, make sure you set it to something, if it is an image find a spacer.gif or something you can use, if it is a script or an Iframe either set it or remove it. If you think about it this makes perfect sense, an image tag with an empty src attribute will end up calling the page as the source, which will fire the page load event again. In my case, I was using an <asp:image> tag that had no imageurl until the submit button was pushed and a green check mark or red cross was assigned to it as part of an onscreen Success/Failure message. Making it default to the check mark image resolved my issue. While researching this I found these other possible causes:

  • Check to see if AutoEventWireUp is set to false in the page/control directive.
  • If you are using Visual Basic, check to see that your Handles keyword is only handling one event:"Handles MyBase.Load, Me.Load" would cause it to fire twice.
  • If it only happens on postback, check that your Javascript form validation does not end with form.submit() which would effectively submit your form twice.

Categories: ASP.Net | C# | VB
Posted by Williarob on Thursday, July 24, 2008 1:23 PM
Permalink | Comments (3) | Post RSSRSS comment feed