Sunding asp.net3.5 Control and Component Development Technology Series-page state mechanism (iii)

Source: Internet
Author: User

6.3 Control state Mechanism

The control state mechanism has been supported since ASP.net 2.0. Control's state data can now be persisted through control state instead of view state, and control state cannot be disabled as view state. Because the state of the control works in exactly the same way as the view state, and by default it is stored in the same hidden field on the page, there is little introduction to how it works.

Similar to LoadViewState and saveviewstate, control states provide a pair of methods, the name of the method is loadcontrolstate and Savecontrol state, and are also provided in the controls base class.

The shaded portion of Figure 6-5 is the stage of control state in the control lifecycle.

If you enable the control state feature, you only need to implement the following methods:

/// <summary>
/// 获得本书更多内容,请看:
/// http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
/// </summary>
public class ControlStatePeriod : WebControl
{
   protected override void OnInit(EventArgs e)
   {
     base.OnInit(e);
     Page.RegisterRequiresControlState(this);
   }
   protected override object SaveControlState()
   {
     //… …
   }
   protected override void LoadControlState(object savedState)
   {
     //… …
   }
}

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.