支持postback
public cass SugaroaInput : WebControl
{
private static readonly object EventTextChanged = new object();
//支持事件
public event EventHandler TextChanged
{
add
{
base.Events.AddHandler(EventTextChanged, value);
}
remove
{
base.Events.RemoveHandler(EventTextChanged, value);
}
}
//post back
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
//Page.ClientScript.ValidateEvent(postDataKey, string.Empty);
string text = this.Text;
string str2 = postCollection[postDataKey];
if (!this.ReadOnly && !text.Equals(str2, StringComparison.Ordinal))
{
this.Text = str2;
return true;
}
return false;
}
//输出html
protected override void Render(HtmlTextWriter writer)
{
if (Page != null)
Page.VerifyRenderingInServerForm(this);
writer.Write("<input ");
writer.WriteAttribute("type", "input");
writer.WriteAttribute("id", this.ClientID );
writer.WriteAttribute("name", this.ClientID );
writer.WriteAttribute("value", this.Text, true);
writer.Write("/> ");
base.Render(writer);
}
//Text change event handler
protected virtual void OnTextChanged(EventArgs e)
{
EventHandler handler = (EventHandler)base.Events[EventTextChanged];
if (handler != null)
{
handler(this, e);
}
}
[Localizable(true), Bindable(true, BindingDirection.TwoWay), PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty), DefaultValue("")]
public virtual string Text
{
get
{
string str = (string)this.ViewState["Text"];
if (str != null)
{
return str;
}
return string.Empty;
}
set
{
this.ViewState["Text"] = value;
}
}
}
具体详见:http://www.cnblogs.com/jackliu185/archive/2009/08/21/1551418.html