The problem is as follows:
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------
Why is the enableviewstate of textbox set to false? After the textbox is sent back, it can still save the input content in the textbox?
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------
Cause:
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------
1. enableviewstate priority:
Global configuration <Program <page <Control
Note: viewstate cannot be disabled for the following server controls
Textbox
Checkbox
Checkbox list
Radiobuttonlist
The status of the above control is processed through the ipostbackeventhandler and ipostbackdatahandler interfaces, rather than the viewstate mechanism, so enableviewstate has no effect.
2. controls that often need to change values. The returned data does not depend on viewstate. The send-back control implements the ipostbackdatahandler interface. In the loadpostdata method of this interface, it judges the returned value and the value in viewstate. If it changes, call the raisepostdatachangedevent method to trigger the corresponding event (textchanged for textbox ). If the returned value in loadpostdata is different from the value in viewstate, the textbox value is set to the returned value. This is what you see.
Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------
Extension:
In ASP. NET, the previous enableviewstate attribute is introduced to each webform control. What is the purpose of this attribute. We know that for webform, the code is on the server side to process client requests. When a user browses a webpage through a browser, the user performs some operations on the webpage, such as opening a new link or clicking a button. In ASP, these are processed by the script language, and then passed to the server. However, in ASP. NET, because code behind technology is used, in coding, the work previously completed by the client is usually put on the server.
So how does the server know the customer's operations? For example, if I enter content in the text box or click the login button, how does the server obtain the information? Without this information, the server cannot respond to the customer's request. The principle is that ASP. NET references the viewstate mechanism. The server stores the status of various controls and pages on the webpage, including the layout and attributes of each control on the page. These values are stored in viewstate. We can observe the HTML source code of the ASPX page. Suppose there is a button and a ListBox control on this page. The HTML file is as follows:
<Input type = "hidden" name = "_ viewstate" value = "ddwzodyzndm5ntu7oz7fvvijbq45bda7qjaumiiohz8moq ="/>
<Input type = "Submit" name = "button1" value = "button" id = "button1" style = "height: 40px; width: 96px; Z-INDEX: 101; left: 200px; position: absolute; top: 240px "/>
<Select name = "listbox1" size = "4" id = "listbox1" style = "width: 152px; Z-INDEX: 102; left: 176px; position: absolute; top: 120px "> </SELECT>
The difference is that, first, the scripting language that must respond to client events is missing, and the other is the attribute named "_ viewstate. The value is a long string of characters. The type is "hidden ". This value records the status information of each control and page. When you perform operations on the page, the status value changes and the changed value is passed to the server. The server compares the differences between the changed status value and the initial value to respond to specific requests.
Once there are many page controls, this frequent transfer of control status values will consume a lot of network resources. Therefore, ASP. NET provides the enableviewstate attribute, and the default value is true. When it is set to true, this control is included when the status value is passed; if it is set to false, it is not included when the status value is passed. Since the status value does not include this control, the client does not respond to the operation on it.
We can make an experiment and write the code in the button#click event:
ListBox. Items. Add ("client click button once !");
In this case, run the application, click the button on the webpage, and add the content to The ListBox. Click the content to add the content. If we change the enableviewstate attribute of ListBox to false and click the button continuously, we can only add it once.
What are the benefits? When developing a web application, you can change the enableviewstate attribute of some controls to false if they do not need to be operated by the user or only need to be operated once, this will optimize our programs and speed up network access.
How to convert the enableviewstate attribute of textbox