4-1/2 Web Page Life Cycle PageLoad Event

(Picture 1)

Postback event:

 IsPostBack = true/false;


Every time a page is loaded, the PageLoad event is executed:

(Figure II)


Routine one:

(Figure 3)


(Picture 4)



Write the code in Figure 3 in the PageLoad event, run the program, and the page effect is as follows:

The current time, the checkBox control, and the DropDownList control are displayed or selected when the page loads;

(Figure 5)


New question:

When the code in Figure 3 is written into the PageLoad event, when the page is loaded, the first text box is set to the password state, the second text box is unavailable, and the third

The text box content is empty. At this point, enter the content in the third text box, click to get the content and split the (Button1) control, the right text box is still not displayed

content; the reason is that when the Button1 control is clicked, the page is reloaded, and the first event that occurs is the PageLoad event, so the third text box's

The content is emptied again, so the bottom text box cannot get any data;


Routine 2: Information entry page

(Picture 6)

 

(Figure 7)



Add the following code to the PageLoad event:

After adding the following code, each time the page is loaded, the default name column is empty, the class column defaults to class two, and the gender defaults to male;

(Figure 8)


(Figure 9)

Information input:



(Figure 10)

After clicking the OK button, the problem is found: when the above two parts of code (Figure 7 and Figure 8) are added to the control at the same time, run the page, and the display results are as follows:


Error reason:



(Figure 11)

asp.net page operation mode:


1) The browser initiates a page request to the server;

2) The server reads the file of the page in its own hard disk (first read);

3) The server compiles the read files to generate XHTML files;

4) Return the compiled page to the browser;

5) If the page returned by the server contains a submit button, when the button is clicked, the browser will return the entire page to the server;

6) The server extracts the necessary information from the returned page as the first part, and retrieves it from the hard disk of the server according to the page sent by the browser.

Original information, combine the necessary information with the original information, recompile, and form a new page (postback page);

7) Return the new page to the browser (one round trip, a whole new page is generated);

Note: The server reads the original page from the hard disk. To compile it, the PageLoad event will be re-executed each time it is compiled.


(Figure 12)

In the figure below, the if(IsPageBack == false) condition is used to determine whether the page is loaded for the first time. If it is the first time, the following code is executed:

IsPostBack is used to determine whether the page is loaded for the first time or a postback page;

(Figure 13)


The order of occurrence of control events: it is related to the position order of the control in the page

(Figure 14)


Note that the execution of the control is executed when the server compiles the page;

The following routine explains the execution order of control events:

(Figure 15)


(Figure 16)

As shown below, in the execution order, PageLoad is always ranked first, ButtonClick is always ranked last, and other events have nothing to do with the order of operations of the controls. As for the order of the controls in the page; do not know the sequence of actions;


Example code:

(Figure 17)


(Figure 18)







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325903974&siteId=291194637