<%@ Page language="C#" %>
<%@ Register TagPrefix="Control" Namespace="Control" Assembly="Control" %>
Creating ViewState-Enabled Control Properties
File: Control.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace Control
{
[DefaultProperty("Text"),
ToolboxData("<{0}:ViewStateControl runat=server>{0}:ViewStateControl>")]
public class ViewStateControl : System.Web.UI.WebControls.WebControl
{
public string Text
{
get
{
string text = (string) ViewState["Text"];
return (text == null)? string.Empty : text;
}
set
{
ViewState["Text"] = value;
}
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(Text);
}
}
}