Asp. NET in IsPostBack usage Detailed _ practical skill

Source: Internet
Author: User
Tags commit

In this paper, the usage of IsPostBack in asp.net is explained in detail, which will help readers to master the usage of IsPostBack in asp.net.

First, IsPostBack Introduction:

Page.IsPostBack is a flag: whether the current request is opened for the first time . The calling method is: Page.IsPostBack or IsPostBack or This.ispostback or this.Page.IsPostBack, they are all equivalent .

1 when opening a URL via IE's address bar, it is opened for the first time, and the page is no longer opened for the first time when it is submitted to the server by submitting a button or by submitting a button to post. (Every time you click the button, it is loaded one at a time)

2) IsPostBack is false at the first time and is true at all times.

3). NET to determine whether a page was first opened: request.form.count>0

4 Every time the page load, according to the need to load every time the code to put in the IsPostBack, only need to load the code once placed in the IF (! IsPostBack).

5 each time the user returned any information to the server, the IsPostBack attribute was raised to determine if the user had ever done a login or other event.

Ii. Conclusions on IsPostBack:

The analysis of the related processing in the. NET source code has the following conclusions:

1 The Ispostback=false of the page migrated to when using Server.Transfer for migration.

2 POST method If request value is not requested, that is, Request.Form =null is ispostback=false;get If request value is not requested, that is Request.QueryString = Null is Ispostback=false.

3 If the QueryString or form has a request value, but the key in the QueryString or form is not "__viewstate" and "__eventtarget" and "__viewstatefieldcount", And no key is "null", the value starts with "__viewstate" and there is no key value pair with a value of "__eventtarget", then Ispostback=false.

4 use Response.Redirect mode to migrate from the picture, this time ispostback=false.

5) A cross-page commit (Crosspagepostback) occurs when accessing the PreviousPage property for the source pageispostback=true.

6 When a cross-page commit (Crosspagepostback) occurs, the target page is Ispostback=false

7 use Server.Execute to migrate to the page of its ispostback=false.

8 The corresponding DLL is updated during page run and the tree structure of the page has changed, in which case the request is ispostback=false.

Conclusion Summary:
General condition Ispostback=false If no value is requested in the request. If you have a request value but do not include some special keys or values such as "__viewstate", then Ispostback=false ( after each request. NET Framework will return some special hidden domain "__viewstate" to the client ). There are special situations where the rules above are not correctly judged and require special handling. These situations include server.transfer,response.redirect,crosspagepostback,server.execute, changes in page elements, and recompilation of .

Related Article

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.