Asp. NET IsPostBack properties that prevent pages from loading multiple times

Source: Internet
Author: User

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

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.