Sandy
Sandy

Reputation: 105

What could be the reason to hit page_load more than once

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

Upvotes: 2

Views: 1689

Answers (3)

codeandcloud
codeandcloud

Reputation: 55268

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

Upvotes: 5

Ta01
Ta01

Reputation: 31630

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.

Upvotes: 1

IrishChieftain
IrishChieftain

Reputation: 15253

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

Upvotes: 3

Related Questions