开发者

ASP.NET Page.IsPostBack

开发者_StackOverflow

I have some code in the load event of my page which should only run the first time the page is loaded, however, it runs everytime 'refresh' is clicked on the browser EVEN THOUGH i am checking for postbacks:

If not page.ispostback then
 ' Code...
End if


Refresh isn't a postback (i.e. there's no POST happening, it's another GET), it's the browser asking for the page all over again. In this case, from the server point of view, it's a fresh request.


The IsPostBack property can only detect requests that were generated by a __doPostBack JavaScript function call. All other requests are treated as new requests since ASP.NET has no way of knowing how the request was generated.

Since the __doPostBack function populates hidden form fields, the ASP.NET runtime is able to detect that the request was generated by a control which posted back. All other requests will not have populated these hidden fields so the runtime does not consider them post-backs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜