A --- Could you tell me why the text attribute of the textbox control cannot be modified during page loading (page_load.
Private void page_load (Object sender, system. eventargs E)
{
This.txt name. Text = "1234"; // The Initial Value 1234 is assigned to the text attribute of txtname of the Textbox Control.
~~~~~~~~~~~~~~~~~~~~~~~~~
}
The text value of txtname is modified after the page is generated. However, in subsequent calls, the text value of txtname is 1234.
For example, you can modify the text value of txtname to 8888 on the page and then trigger the button event,
Call
Name = this.txt name. Text. Trim ();
But the value of name is still 1234.
B --- A: page_load will be called at any time, so it must be 1234.
C --- A: Do not write in page_load.
If this is the first change, use if (! Ispostback)
{
............
}
D --- answer: If (! Ispostback)
{
This.txt name. Text = "1234 ";
}
Positive Solution
E ---- answer :! Page. ispostback
Otherwise, your page_load event is automatically executed every time you refresh or request the page. The page_load is different from the form_load in VB. The load in VB is only once, whereas ASP. . Net.
The clearest explanation is:
Ispostback = false when a page is displayed for the first time
Ispostback = true when you click the button or other items to submit on this page.
In general, the content in this function refers to what needs to be done when the page is opened for the first time.
Initialize something.
Suppose you define textbox as null in page_load (), and write a segment of textbox value to the data inventory in the button_click event. after you enter a value in the textbox and click the button, you can save the value entered in the textbox to the database. in fact, when you click a button, the system will automatically re-Execute page_load (), that is, clear the textbox of the handle, and then execute the click event, the value you save to the database is always empty. therefore, add If (! Ispostback ).