自定义控件的问题!!!!!!!!!!!

cyp503 cyp503 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位,我按照.net framework帮助文档做了一个自定义控件,源代码如下:

using System;
using System.Web.UI;
using System.Collections;
using System.Collections.Specialized;

namespace WebControlLibrary
{

public class TestButton: System.Web.UI.WebControls.WebControl, IPostBackEventHandler
{

// Defines the Click event.
public event EventHandler Click;

//Invoke delegates registered with the Click event.
protected virtual void OnClick(EventArgs e)
{

if (Click != null)
{
Click(this, e);
}
}


// Define the method of IPostBackEventHandler that raises change events.
public void RaisePostBackEvent(string eventArgument)
{

OnClick(new EventArgs());
}


protected override void Render(HtmlTextWriter output)
{
output.Write("<INPUT TYPE = submit name = " + this.UniqueID +
" Value = 'Click Me' />");
}
}
}

编译后引用,这个自定义控件完全没问题.注意:直到这里没问题

后来,我又做了一个自定义控件,这个控件嵌入上述控件TestButton,

新作的这个控件也可以实现页面回发,因为实现了IPostBackEventHandler接口

但问题出现在"虽然已经可以实现页面回发,但服务器端不能判断是由于哪个控件引起的"

即:

MyCustomButton btn=new MyCustomButton();
btn.Click+=new EventHandler(this.btnClick);

private void btnClick(object sender,EventArgs e)
{
Response.Write("hello world!"); //这里不能输出!!
}
...全文

相关推荐

评论 21
收藏 已收藏
分享
返回顶部
cyp503
.NET社区 62,272 成员 668,968 内容