CheckMSDN,Top ThereIsPostBackdefinition: Gets a value that indicates whether the page is being loaded in response to a client postback, or whether it is being loaded and accessed for the first time. If the page is loaded in response to a client postback ;true ; otherwise false .
First, there is a question of how the Web page is loaded, the client browser server sends the request, the server side sends the request to the client, and the server side releases the client's request.
The second question, why to prevent the page multiple loading, according to the above loading process we know that when the second time the same request, the server side did not save the original client data, then show to the client browser is empty or still the original information.
For example a simple login code is as follows:
protected void Page_Load (object sender, EventArgs e) { this.txtUserName.Text = ""; This.txtUserPwd.Text = ""; This.btnexit. Attributes. ADD ("onclick", "window.close ();"); } protected void Btnlogin_click (object sender, EventArgs e) { if (This.txtUserName.Text = = "a" && This.txtUserPwd.Text = = "a") { This.lblMessage.Text = "Login successful"; } else {this . lblmessage. Text = "Login Failed"; } }
The interface shown is as follows: The first time you enter the wrong user name and password will prompt login failure.
When I re-enter the correct user name and password: the page still fails to commit.
The reason is that the system did not respond again after clicking Login.
Solution: Change the above code to:
protected void Page_Load (object sender, EventArgs e) { if (! Page.IsPostBack) { this.txtUserName.Text = ""; This.txtUserPwd.Text = ""; } This.btnexit. Attributes. ADD ("onclick", "window.close ();"); } protected void Btnlogin_click (object sender, EventArgs e) { if (This.txtUserName.Text = = "a" && This.txtUserPwd.Text = = "a") { This.lblMessage.Text = "Login successful"; } else {this . lblmessage. Text = "Login Failed"; } }
Changes to the interface display
&NBS P , &NB sp;
Sort out some of the online summaries that can be understood at this stage:
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 QueryString or form
Key "__viewstate" and "__eventtarget" and "__viewstatefieldcount", and no key is "null", the value starts with "__viewstate" and there is no value "__eventtarget" The key-value pair, then Ispostback=false.
Conclusion ④ is ispostback=false when the Response.Redirect mode is used to migrate from the picture.
The first contact with ASP. This blog is for beginners ' understanding only. Please correct me if you have any mistakes.
Asp. NET IsPostBack properties that prevent pages from loading multiple times