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

Source: Internet
Author: User

6.2.4 implementation of custom type view state

The concepts and principles of the previous view state have been made clear, and this section illustrates how viewstate works in one instance. Create a Web custom control Viewstatecontrol that inherits from WebControl or control, and the code is as follows:

///<summary>
///get more from this book, see:
///http://blog.csdn.net/ChengKing/archive/2008/08/18/ 2792440.aspx
///</summary>
[ToolBoxData ("<{0}:viewstatecontrol runat=server></{0}: Viewstatecontrol> ")]
public class Viewstatecontrol:webcontrol
{
}
because WebControl is inherited from the control base class , the control already has the ability to perform methods LoadViewState and saveviewstate in the view phase of the control life cycle. Add three different types of properties to the control, as follows:
///<summary>
///get more from this book, see:
///http://blog.csdn.net/ChengKing/archive/ 2008/08/18/2792440.aspx
///</summary>

private string _text;
[Bindable (True)] 
[DefaultValue (")]
[Localizable (true)]
[Category (Test View state)]
[Description (" No view state store is used ")]
Public    String Text_noviewstate
{
Get
{
return _text;
  
Set
{
This._text = value;

}

[Bindable (True)]
[DefaultValue (")]
[Localizable (true)]
[Category (Test View state)]
[ Description ("Use the ViewState property to saveStored data this property ")]
public string text_viewstate
{
Get
{
String s = (string) viewstate[" Text_viewstate "]; 
Return ((s = = null)? STRING.EMPTY:S);
}
Set
{
viewstate["text_viewstate"] = value;

}
}

Private Facestyle _facestyle;
[PersistenceMode (Persistencemode.innerproperty)]
[DesignerSerializationVisibility (designerserializationvisibility.content)]
[Notifyparentproperty (True)]
[Category (Test View state)]
[Description (Custom view state (implementing the IStateManager Interface) stores this property)]
public Facestyle facestyle
{     
Get
{
if (_facestyle = null)
{
_facestyle = new Facestyle ();

if (istrackingviewstate)
{
(IStateManager) _facestyle). TrackViewState ();   
}
Return _facestyle
}
}

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.