- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
用户自定义开发一个按钮
1.新建用户控件,取名为UCButton.ascx,并使定义类继承自IPostBackEventHandler。
2.给按钮增加属性及事件:
代码 private bool mUseBind true; private string mUrl #; public string ButtonClass get; set; public string ButtonId get; set; public string ButtonText get; set; public string ButtonStyle get; set; public string OnClientClick get; set; // If this user control used in a grid view or the other Databinding methods, you need to set this attribute value to false [DefaultValue true ] public bool UseBind get return mUseBind; set mUseBind value; public string Url get return mUrl; set mUrl value; public string AdditionalAttributeAndValue get; set; public event EventHandler Click;
3.重写Render方法如下:
代码 protected override void Render HtmlTextWriter output string clientClick ; string buttonStyle ; if !string.IsNullOrEmpty this.ButtonStyle buttonStyle style +this.ButtonStyle+; if !string.IsNullOrEmpty this.OnClientClick clientClick onclick + this.OnClientClick + @; string html @ div class + this.ButtonClass + @+clientClick+buttonStyle+@ +AdditionalAttributeAndValue+@ div class left div class right + this.ButtonText + @ div class lower div class left div class right ; if this.Click null output.WriteLine html ; else if this.mUrl ! # output.WriteLine a href \+this.mUrl+\ + html + ; else output.WriteLine a href \#\ onclick \ 0 \ + html + , this.Page.ClientScript.GetPostBackEventReference this, ; 4.修改Pageload事件:
代码 protected void Page_Load object sender, EventArgs e if this.UseBind try this.DataBind ; catch Exception throw new Exception Please make sure that you set UseBind false when using Databinding methods such as Eval , XPath , and Bind . ; 5.添加以下方法以触发事件:
代码 public void RaisePostBackEvent string eventArgument if this.Click ! null this.Click this, new EventArgs ; 6.保存全部,这个自定义按钮就可以使用了。
注意事项:
1.在用户事件中如果要使用变量,不能使用 % 变量名称% ,而是要用 %#变量名称% 2.如果用户控件中使用了this.DataBind 方法。则在控件中不能使用诸如Bind ,Eval 之类的方法。
您可能关注的文档
最近下载
- 关于十二矿优化劳动组织的调研报告.docx VIP
- 沪粤版九年级物理上册知识点整理.pdf VIP
- 关于十二矿优化劳动组织的调研报告.doc VIP
- 2025年财会类中级会计职称中级会计实务-中级会计实务参考题库含答案解析(5套试卷).docx VIP
- 旅游咨询项目创业计划书.pptx VIP
- 西师版数学六年级上册全册教案.pdf VIP
- 2025江西鹰潭市公安局面向社会招聘留置看护勤务辅警87人笔试备考试题及答案解析.docx VIP
- 浅析互联网金融平台的风险与监管——以蚂蚁金服为例.doc VIP
- 旅游咨询创业计划书.pptx VIP
- 【0181】46页PPT数字化建设项目总体规划蓝图(豪华版).pptx VIP
文档评论(0)