using System;
using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;namespace PEONormalControl...{ /**//// <summary> /// 回传事件参数类型 /// </summary> public class EventTextBoxEventArgs:EventArgs ...{ private string _ToAppend; EventTextBoxEventArgs() ...{ } public EventTextBoxEventArgs(String ArgText) ...{ this._ToAppend=ArgText; } /**//// <summary> /// 回传事件参数 /// </summary> public String ArgText ...{ get...{return _ToAppend;} set...{_ToAppend =value;} } } /**//// <summary> /// 从TextBox继承,实现了IPostBackEventHandler接口 /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:EventTextBox runat=server></{0}:EventTextBox>")] public class EventTextBox : System.Web.UI.WebControls.TextBox,IPostBackEventHandler ...{ //private string text; private static readonly object objEventChangedKey; public delegate void EventChangedHandler(object sender,EventTextBoxEventArgs e); [Bindable(false), Category("Appearance"), DefaultValue("")] public string PrefixText ...{ get ...{ if (ViewState["PrefixText"] == null) return ""; else return ViewState["PrefixText"].ToString() ; } set ...{ ViewState["PrefixText"] = value; } } /**//// <summary> /// 引起回传的事件名称 /// </summary> [Bindable(false), Category("Behavior"), DefaultValue(""),Description("引起回传的事件名称")] public string EventName ...{ get ...{ if (ViewState["EventName"] == null) return ""; else return ViewState["EventName"].ToString() ; } set ...{ ViewState["EventName"] = value; } } /**//// <summary> /// 回传事件参数 /// </summary> [Bindable(false), Category("Behavior"), DefaultValue(""),Description("回传事件参数")] public string EventArgText ...{ get ...{ if (ViewState["EventArgText"] == null) return ""; else return ViewState["EventArgText"].ToString() ; } set ...{ ViewState["EventArgText"] = value; } } /**//// <summary> /// 用户自定义的回传函数 /// </summary> [Bindable(false), Category("Behavior"), DefaultValue(""),Description("用户自定义的回传函数,为空则使用标准的回传函数")] public String UserPostBackFunction ...{ get ...{ if (ViewState["UserPostBackFunction"] == null) return ""; else return ViewState["UserPostBackFunction"].ToString() ; } set ...{ ViewState["UserPostBackFunction"] = value; } } protected virtual void OnEventChanged(EventTextBoxEventArgs e) ...{ EventChangedHandler handler1 = (EventChangedHandler) base.Events[objEventChangedKey]; if (handler1 != null) ...{ handler1(this, e); } } public void RemoveStateView(String strKey) ...{ this.ViewState.Remove(strKey); } [Description("EventTextBox_OnEventChanged"), Category("Action")] public event EventChangedHandler EventChanged ...{ add ...{ base.Events.AddHandler(objEventChangedKey, value); } remove ...{ base.Events.RemoveHandler(objEventChangedKey, value); } } /**//// <summary> /// 将此控件呈现给指定的输出参数。 /// </summary> /// <param name="output"> 要写出到的 HTML 编写器 </param> protected override void Render(HtmlTextWriter output) ...{ EventChangedHandler handler1 = (EventChangedHandler) base.Events[objEventChangedKey]; if (handler1 != null && EventName != String.Empty) ...{ base.Attributes[EventName]=UserPostBackFunction==""? Page.GetPostBackClientEvent(this,EventArgText):UserPostBackFunction; if(PrefixText != "" && !base.Text.StartsWith(PrefixText)) base.Text = PrefixText + base.Text; } base.Render(output); } //增加自己想渲染的属性 protected override void AddAttributesToRender(HtmlTextWriter writer) ...{ //writer.AddAttribute(HtmlTextWriterAttribute.Title,"PEOControl"); base.AddAttributesToRender (writer); } IPostBackEventHandler 成员#region IPostBackEventHandler 成员 public void RaisePostBackEvent(string eventArgument) ...{ // TODO: 添加RaisePostBackEvent 实现 EventTextBoxEventArgs e = new EventTextBoxEventArgs(eventArgument); OnEventChanged(e); } #endregion }}