We also discuss how to save the custom viewstate of Asp.net 2.0.

Source: Internet
Author: User
Tags printable characters
I saw an article about how to save the custom viewstate. I found that this feature was not used. I tried it and wrote the attributes in my custom base class basepage, sessionpagestatepersister is used. /// <summary>
/// Use the viewstate of the session storage page
/// </Summary>
Protected override pagestatepersister
{
Get
{
Return new sessionpagestatepersister (this );
}
}

After some debugging and observation, we found that the length of the viewstate field is 2177 if this attribute is not enabled on a moderately complex page (about 20 controls, after this attribute is used, the length of the viewstate field is changed to 488 bytes, but it does not completely disappear. so what else does it save? I tried to decode the base64 encoding and found that sessionid is mainly composed of the Control ID, and there is no attribute value (which are non-printable characters .), the decoded viewstate content on this page is as follows: Alert ('h8c827ec3c056380 _ controlsrequirepostbackkey __
Editcontrol $ datepicker1editcontrol $ clientidctleditcontrol $ clientidctl $ tvdiceditcontrol $ clientid2ctleditcontrol $ clientid2ctl $ tvdiceditcontrol $ typeidctleditcontrol $ typeidctl $ tvdiceditcontrol $ dictionarytree1! Editcontrol $ dictionarytree1 $ tvdiceditcontrol $ commencingdatectl ": Z [hktvw ');

It looks like an index. Although viewstate hidden fields still exist, using this attribute can significantly reduce the number of bytes downloaded to the browser on the page! Wonderful!

If necessary, you can write a pagestatepersister inheritance class to write the content to the database. Of course, if the load is not large, and the memory is sufficient, you can simply save it in the session. [Note: moreover, sessions can also be used to customize storage locations]. let's start using this feature today!

Related Article

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.