服务器控件开发 绑定事件
来源:互联网 发布:杀马特遇见洗剪吹 知乎 编辑:程序博客网 时间:2024/05/16 06:26
using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Collections.Specialized;namespace ServerControl{ [DefaultProperty("Text")] [DefaultEvent("TextChanged")] [ToolboxData("<{0}:KingTextBoxCanPostevent runat=server></{0}:KingTextBoxCanPostevent>")] public class KingTextBoxCanPostevent : Control,IPostBackDataHandler,IRaiseItemChangedEvents { public KingTextBoxCanPostevent() { } public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? String.Empty : s); } set { ViewState["Text"]=value; } } public bool AutoBostBack { get; set; } protected override void OnPreRender(EventArgs e) { PostBackOptions pbo = new PostBackOptions(this); pbo.AutoPostBack = AutoBostBack; pbo.PerformValidation = true; pbo.TrackFocus = true; pbo.ClientSubmit = true; pbo.RequiresJavaScriptProtocol = false; string strPostBackCode = this.Page.ClientScript.GetPostBackEventReference(pbo); StringBuilder strPostBackFromClient = new StringBuilder(); strPostBackFromClient.Append(" function PostBackFromClient_"+this.ClientID+"()"); strPostBackFromClient.Append("{"); strPostBackFromClient.Append(strPostBackCode+";"); strPostBackFromClient.Append("}"); if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "PostBackFromClient_" + this.ClientID)) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"PostBackFromClient_"+this.ClientID,strPostBackFromClient.ToString(),true); } base.OnPreRender(e); } protected override void Render(HtmlTextWriter writer) { //base.Render(writer); StringBuilder sb = new StringBuilder(); sb.Append("<input type=\"text\" name="); sb.Append("\""+this.UniqueID+"\""); sb.Append(" value="); sb.Append("\"" + HttpUtility.HtmlEncode(Text)+ "\""); sb.Append(" onblur='" + "PostBackFromClient_" + this.ClientID + "();'"); sb.Append(" />"); writer.Write(sb.ToString()); } public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) { string strOldValue = Text; string strNewValue = postCollection[this.UniqueID]; if (strOldValue == null || (strOldValue != null && !strOldValue.Equals(strNewValue))) { this.Text = strNewValue; return true; } return false; } public event EventHandler TextChanged; protected virtual void OnTextChanged(EventArgs e) { if (TextChanged != null) { TextChanged(this, e); } } #region IRaiseItemChangedEvents Members public bool RaisesItemChangedEvents { get { throw new NotImplementedException(); } } #endregion #region IPostBackDataHandler Members public void RaisePostDataChangedEvent() { OnTextChanged(EventArgs.Empty); } #endregion }}-------------------------------------------------------------------------------------
复合控件的事件处理机制:
private static readonly object TextChangedKeyObject = new object(); public event EventHandler TextChanged2 { add { base.Events.AddHandler(TextChangedKeyObject, value); } remove { base.Events.RemoveHandler(TextChangedKeyObject, value); } } protected virtual void OnTextChanged2(EventArgs e) { EventHandler handler = base.Events[TextChangedKeyObject] as EventHandler; if (handler != null) { handler(this, e); } }
- 服务器控件开发 绑定事件
- 利用ajax为服务器控件绑定事件
- 绑定控件事件
- Jquery控件绑定事件
- iOS控件绑定事件
- HTML 控件绑定事件
- C#开发学习笔记:动态绑定控件事件
- 数据绑定服务器控件
- 数据绑定服务器控件
- 数据绑定服务器控件
- 数据绑定服务器控件
- 绑定DataList服务器控件
- Asp.net控件开发学习笔记(八)----服务器控件事件
- Asp.net控件开发学习笔记(九)----服务器控件事件
- 绑定用户控件button事件
- 查看控件的事件绑定
- ASP.NET2.0服务器控件开发之实现事件
- ASP.NET2.0服务器控件开发之实现事件
- 杂
- c++中static的作用
- 代码示例:递归遍历文件夹实现目录拷贝
- NSString字符串常用方法
- Oracle的云计算
- 服务器控件开发 绑定事件
- Android发送彩信(带图片附件)
- 强耦合与松耦合的不同,认真查了有什么不同之处,与大家分享!
- helloPe的android项目实战之连连看—设计篇
- WCF托管服务和客户端代理
- Orders
- 添加Silverlight单元测试项目模板
- Windows Phone 7 自定义按钮的实现
- Telecomm Standards