.NET's use of ViewState

xiaoxiao2021-03-06  115

ViewState's working principle ViewState is a mechanism, ASP.NET uses this mechanism to track server control status values, otherwise these values ​​will not be sent back as part of the HTTP form. For example, the text displayed by the Label control is saved in ViewState by default. As a developer, you can bind the data, or only set up the Label programming when loading this page. In subsequent return, the label text will automatically refill from ViewState. Therefore, in addition to cumbersome work and code, ViewState can also reduce the number of round trips of the database. ViewState does not have any mystery, which is a hidden form field managed by the ASP.NET page framework. When ASP.NET performs a page, the ViewState value and all controls on this page will be collected and formatted into an encoded string and then assigned to the value attribute of the hidden form field (ie). Since the hidden form field is part of the page sent to the client, the ViewState value is temporarily stored in the client's browser. If the client selects the page back to the server, the ViewState string will also be passed back. The viewState form field and its return value can be seen in Figure 2 above. After passing, the ASP.NET page frame will parse the ViewState string and populate the ViewState property for the page and each control. The control then uses ViewState data to restore yourself to the previous state.

About ViewState has three small problems worth noting. If you want to use ViewState, you must have a server-side form tag in the ASPX page.

转载请注明原文地址:https://www.9cbs.com/read-125383.html

New Post(0)