A misunderstanding: Why is the enableviewstate of textbox invalid when it is set to false?

Source: Internet
Author: User
The enableviewstate attribute of the page object is false, meaning that the viewstate of the entire page (including all server-side controls) is disabled, however, <input type = "hidden" name = "_ viewstate" value = ".... "/> does not disappear. viewstate does not work at this time.

The text content of textbox is placed in the data set of post to the server, and textbox implements the ipostbackdatahandler interface, which calls ipostbackdatahandler before the page_load event. the loadpostdata method updates the response textbox Based on the name attribute of the Post-returned HTML element and the uniqueid attribute of the server-side control. text attribute. If the new data is different from the old text attribute, loadpostdata returns true, so that the later raisepostdatachangedevent will be called, this event will finally call the ontextchanged method to trigger textbox. textchanged event, and then, in the render event, textbox will render its text attribute, so that the final displayed textbox content will remain. (Note: The uniqueid attribute is very important here. You must set the name attribute to uniqueid during render; otherwise, the loadpostdata method cannot find the correct server-side control match, for more information, see "processing PostBack Data ")

Note: although the text attribute of textbox is implemented using viewstate, viewstate is disabled at this time, however, if viewstate is disabled, it means that the loadviewstate and saveviewstate methods do not save the viewstate object content in the server content in <input type = "hidden" name = "_ viewstate" value = ".. .. "/> the viewstate object in the memory can still be used. It can be proved as follows:
Private void page_load (Object sender, system. eventargs E)
{
This. viewstate ["test"] = "test ";
This. response. Write (this. viewstate ["test"]. tostring ());
}

When viewstate is disabled, the "test" string will still be written, which indicates that the viewstate object in the memory can still be used.

For more information about the server-side controls that return post data, see "control execution lifecycle"
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpguide/html/cpconcontrolexecutionlifecycle. asp

"Processing PostBack data"
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/cpguide/html/cpconreceivingpostbackdatachangedications ications. asp

The following Article describes the detailed implementation of the simulated textbox Source Code :
"PostBack data processing sample"
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconpostbackdataprocessingsample.asp

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.