There are couple of Classes and interfaces that you can use:(inherit)
- WebControl
- IPostbackDataHanlder
- INamingContainer
Example:
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public class CustomTextBox : WebControl,
IPostBackDataHandler,
INamingContainer
{
public string Text
{
get
{
return (string)(ViewState["Text"] ?? (ViewState["Text"] = string.Empty));
}
set
{
ViewState["Text"] = value;
}
}
public bool AutoPostBack { get; set; }
public event EventHandler TextChanged;
public virtual bool LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
string postedValue = postCollection[postDataKey];
this.Text = postedValue;
return false;
}
public virtual void RaisePostDataChangedEvent()
{
OnCheckChanged(EventArgs.Empty);
}
protected virtual void OnCheckChanged(EventArgs e)
{
if (TextChanged != null)
TextChanged(this, e);
}
protected override void Render(HtmlTextWriter output)
{
output.Write(string.Format("<input type='text' id='{0}' name='{1}' value='{2}'{3} />",
this.ClientID,
this.UniqueID,
this.Text,
this.AutoPostBack ? string.Format(
" onclick=\"javascript:__doPostBack('{0}','');\"",
this.UniqueID) :
string.Empty));
}
}
No comments:
Post a Comment