Asp. NET in the understanding of IsPostBack

Source: Internet
Author: User

IsPostBack is a property of the page class, and the return value is a Boolean value. Typically placed in the Page_Load event, this is the first time the page is called. When the page is opened for the first time, its value is false if the current page is a committed page with a value of true. in layman's words, when your page first logs in, it calls the IF (! Page.IsPostBack) {... }, and when the page is not closed before it is re-entered (for example, the statement in {} that returns the page with back<-) is no longer called;

Why are there multiple requests for the same form?      The introduction of server-side events in ASP., a control that supports server-side events, makes a request for the current form, so in many cases we need to distinguish whether it is the first request to the form. If it is only necessary to perform some of the settings on the page, you can put it inside. There are features that speed up.

Page.IsPostBack property, gets a value that indicates whether the page is loading in response to a client postback, or whether it is being loaded and accessed for the first time. [C #] public bool IsPostBack {get;} [JScript] public function Get IsPostBack (): Boolean;

example [C #] void Page_Load ()

{if (!         IsPostBack) {//Validate initially to force asterisks//to appear before the first roundtrip.     Validate (); }} [JScript] function Page_Load () {if (!         IsPostBack) {//Validate initially to force the asterisks//to appear before the first roundtrip.     Validate (); }

. NET source code, the analysis of related processing is concluded as follows: Conclusion ① is the ispostback=false of the page migrated to when migrating with Server.Transfer. Conclusion ②post method If request does not have the requested value, that is, Request.Form =null the Ispostback=false;get method if the request does not have the requested value, that is Request.QueryString = Null is Ispostback=false. Conclusion ③ if the QueryString or form has a request value, but the key in QueryString or form does not have "__viewstate" and "__eventtarget" and "__viewstatefieldcount", And there is no key of "null", the value begins with "__viewstate" and there is no key value pair that has a value of "__eventtarget", then Ispostback=false. Conclusion ④ is ispostback=false when the Response.Redirect mode is used to migrate from the picture. Conclusion ⑤ has a cross-page commit (Crosspagepostback), which is the source page,ispostback=true when accessing the PreviousPage attribute. Conclusion ⑥ when a cross-page commit (Crosspagepostback) occurs, the target page is the Ispostback=false conclusion ⑦ the Server.Execute of the page to which the Ispostback=false was migrated. Conclusion ⑧ has its corresponding DLL updated during page run and the tree structure of the page has changed, in which case the request is ispostback=false.     can understand these conclusions in this way: The general case is ispostback=false if there is no request value. 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 return some special hidden domain "__viewstate" to the client after each request). There are special cases where the above rules are not correctly judged and need special treatment, These scenarios include Server.transfer,response.redirect,crosspagepostback,server.execute, where page element changes and recompilation occur.

ASP. NET IsPostBack understanding of the

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.