2

When I click the Button I am loading one page. i am having some controls in the page_load.

but the problem is my page_load is hitting more than once.

Please can any body explain me what could be the possible reasons for hitting the page_load multiple times.

Thanks

3 Answers 3

5

Is hitting Page_Load twice your issue?

Most probably its due to asp:Image or img without src defined.

To quote mbanavige of ASP.NET Forums,

if you have an img tag with an empty/missing src attribute, then the browser may re-request the current page (or may request the default page) why trying to satisfy the empty src for that img tag.

Another possibility that occurs from time to time is that the page_load event has been wired up twice.

Related: page loads twice in Google chrome

1
  • What do you want me to do if I have something like this in my page.<%-- <Background BackgroundImageUrl="SPREADCLIENTPATH:/img/cbbg.gif"></Background>--%>
    – Sandy
    Aug 17, 2011 at 15:27
3

This is by design. In the page life-cycle it is called on the initial request and on the postback.

http://msdn.microsoft.com/en-us/library/ms178472.aspx

1

ASP.NET webforms are self-posting, so Page_Load will hit hit everytime a time a post back occurs. If you would like to only execute certain code on initial page load, add the following to your Load event handler:

if (!Page.IsPostback)
{
 // Code here
}

This says only execute this code if this is the first request to this page.

2
  • But second time also its saying Ispostback is true.
    – Sandy
    Aug 17, 2011 at 15:12
  • The second time IsPostBack will be true.
    – Ta01
    Aug 17, 2011 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.