开发者

What could be the reason to hit page_load more than once

开发者 https://www.devze.com 2023-03-28 22:48 出处:网络
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.

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 b开发者_C百科ody explain me what could be the possible reasons for hitting the page_load multiple times.

Thanks


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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消