Asp. NET in IsPostBack detailed

Source: Internet
Author: User

1, IsPostBack introduction
page.ispostback is a flag: whether the current request is opened for the first time. The call methods are: Page.IsPostBack or IsPostBack or This.ispostback or This.Page.IsPostBack, both of which are equivalent.
1) when opening a URL through IE's address bar, etc., is the first time it is opened, when passed causes the submitted button to post the server, the page is no longer the first time you open the 2) IsPostBack only when the first opening is false, the other time is true
3). NET determines whether a page is opened for the first time: Request.form.count>0
4) Each time the page loads, the code to be loaded every time, as needed, is placed in IsPostBack, just The code loaded once is placed in the IF (! IsPostBack).
5) The IsPostBack property is raised every time a user callbacks any information from the server to determine that the user is

Have you ever done any landing or other events?
6 if (! IsPostBack)
{
Response.Write ("First time submitted!");
}
if (IsPostBack)
{
Response.Write ("press button!");
}
2 IsPostBack Conclusion
I'm right. NET source code in the relevant processing of the analysis obtained the following conclusions:
Conclusion ① is the ispostback=false of the page migrated to when migrating with Server.Transfer.
Conclusion ②post method if the request does not have the requested value, that is, Request.Form =null ispostback=falseThe Get method is ispostback=false if the request does not have the requested value, that is, Request.QueryString =null.
Conclusion ③ if the QueryString or form has a request value, but the key in the QueryString or form does not"__viewstate" and "__eventtarget" and "__viewstatefieldcount", and there are no keysis "null", the value begins with "__viewstate" and there is no key-value pair with the value "__eventtarget", thenIspostback=false.
Conclusion ④ is ispostback=false when the Response.Redirect mode is used to migrate from the picture.
Conclusion ⑤ a cross-page commit (Crosspagepostback), when accessing the PreviousPage attribute, forSOURCE Pageispostback=true. Conclusion ⑥ when a cross-page commit (Crosspagepostback) occurs, the target page is Ispostback=false
Conclusion ⑦ uses Server.Execute to migrate to a page whose ispostback=false.
Conclusion ⑧ the corresponding DLL is updated during page run and the tree structure of page has changed, this situationIspostback=false at the time of request.
It is possible to understand these conclusions: the general situation is that if there is no requested value in the request Ispostback=false. If you have a request value but do not include some special keys or values such as "__viewstate", then Ispostback=false (the. NET Framework will have some special hidden fields after each request )

"__viewstate", etc. returned to the client). There are special cases where the above rules are not correctly judged and require special treatment, including Server.Transfer, Response.redirect,crosspagepostback,server.execute, Fat
The page element was changed and recompiled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.