📄 webcustomcontrol1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Specialized;
namespace WebIpostBackDataHandler
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
public class WebCustomControl1 : WebControl, IPostBackDataHandler
{
public String Text
{
get
{
return (String)ViewState["Text"];
}
set
{
ViewState["Text"] = value;
}
}
public event EventHandler TextChanged;//定义文本框事件
public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{//重写方法判断文本框是否有回发数据
String presentValue = Text;
String postedValue = postCollection[postDataKey];
if (presentValue == null || !presentValue.Equals(postedValue))
{
Text = postedValue;
return true;//返回值为True,调用此方法后,将调用RaisePostDataChangedEvent方法引发事件
}
//返回值为false,调用此方法后,将不会调用RaisePostDataChangedEvent方法引发事件
return false;
}
public virtual void RaisePostDataChangedEvent()//重定方法引用事件
{
OnTextChanged(EventArgs.Empty);
}
protected virtual void OnTextChanged(EventArgs e)
{
if (TextChanged != null)
TextChanged(this, e);
}
protected override void Render(HtmlTextWriter output)
{
output.Write("<INPUT type= text name = " + this.UniqueID
+ " value = " + this.Text + " >");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -