The Control base class in ASP. NET clears the Page Status

Source: Internet
Author: User

During control development, you sometimes need to clear the Page Status of the Child control. For example, when creating a child control, the following is an Application Scenario for clearing the view and creating a child control during data binding:

Public override void DataBind ()
{
Base. OnDataBinding (EventArgs. Empty );
Controls. Clear ();
ClearChildViewState (); // clear view status
TrackViewState ();
CreateControlHierarchy (true );
ChildControlsCreated = true;
}

This section describes several methods to clean up the page status, which are mainly 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 status settings. If any child control has saved view status information, true is returned; otherwise, false is returned.

2. IsChildControlStateCleared Method

Gets a value that indicates whether the control contained in the current control has the control status. If the control status is not used for its child level, true is returned; otherwise, false is returned.

3. ClearChildState Method

The view status and control status of the sub-control are also cleared. The method is as follows:

Protected void ClearChildState ()
{
This. ClearChildControlState ();
This. ClearChildViewState ();
}

4. ClearChildControlState Method

Clear the control status. The Code is as follows:

Protected void ClearChildControlState ()
{
If (this. ControlState> = ControlState. Initialized)
{
This. flags. Set (0x40000 );
If (this. Page! = Null)
{
This. Page. RegisterRequiresClearChildControlState (this );
}
}
}

The control status is through the method:

Page. RegisterRequiresControlState (this );

Register a control as a control in the persistent control state. You must also call the following methods:

This. Page. RegisterRequiresClearChildControlState (this );

Clears the control status. The difference is that this method is an internal method. It is not called by developers and can only be indirectly called through the ClearChild ControlState method.

5. ClearChildViewState Method

This method mainly clears the view status of the child control. The code structure is as follows:

Protected void ClearChildViewState ()
{
If (this. _ occasionalFields! = Null)
{
This. _ occasionalFields. ControlsViewState = null;
}
}

The IDictionary object ControlsViewState for setting the control view status in the method body is null.

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.