当前位置: 代码迷 >> ASP.NET >> webControl自定义控件事件怎么调用
  详细解决方案

webControl自定义控件事件怎么调用

热度:4719   发布时间:2013-02-26 00:00:00.0
webControl自定义控件事件如何调用?
webControl自定义控件事件如何调用?
我想要封装一些控件在一个自定义里头,如何写事件和页面互动?


------解决方案--------------------------------------------------------
继承IPostBackEventHandler,用RaisePostBackEvent注册

public delegate void PageIndexHandler(string pIndex);
[DefaultProperty( "Text ")]
[ToolboxData( " <{0}:LocalPageFootControl runat=server> </{0}:LocalPageFootControl> ")]
public class TestControl : WebControl,IPostBackEventHandler
{
public event PageIndexHandler PageIndexChange;
protected virtual void OnClick(string pIndex)
{
if (PageIndexChange != null)
PageIndexChange(pIndex);
}

void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
OnClick(eventArgument);
}

protected override void RenderContents(HtmlTextWriter output)
{
StringBuilder builder = new StringBuilder( " ");

builder.Append( " <input type=\ "button\ " class=\ "input_button\ " name=\ "index\ " " + i.ToString() + " value=\ " " + i.ToString() + "\ " OnClick=\ " " + this.Page.ClientScript.GetPostBackEventReference(this, i.ToString()) + "\ " /> ");
output.Write(builder.ToString());
}
  相关解决方案