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

Source: Internet
Author: User

6.6 Clear Page Status

Sometimes you need to clear the page state of a child control when it is developed, such as when you create a child control, which is a scenario that clears the view and creates a child control at data binding time:

/// <summary>
/// 获得本书更多内容,请看:
/// http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
/// </summary>
public override void DataBind()
{
   base.OnDataBinding(EventArgs.Empty);
   Controls.Clear();
   ClearChildViewState(); //清理视图状态 
   TrackViewState();
   CreateControlHierarchy(true);
   ChildControlsCreated = true;
}

This section describes several ways to clean up the page state, primarily provided by the control base class.

1. Haschildviewstate method

Gets a value that indicates whether the child control of the current server control has any saved view state settings. Returns true if any child controls have saved view state information, otherwise false.

2. Ischildcontrolstatecleared method

Gets a value that indicates whether the control contained in the current control has control state. True if the control's child does not use control state, otherwise it returns false.

3. Clearchildstate method

Clears both the view state and the control state of the child control. The method body is as follows:

protected void ClearChildState()
{
   this.ClearChildControlState();
   this.ClearChildViewState();
}
4.ClearChildControlState方法 
清除控件状态。其代码如下:
protected void ClearChildControlState()
{
   if (this.ControlState >= ControlState.Initialized)
   {
     this.flags.Set(0x40000);
     if (this.Page != null)
     {
       this.Page.RegisterRequiresClearChildControlState(this);
     }
   }
}

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.