自定义控件的问题!!!!!!!!!!!
各位,我按照.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!"); //这里不能输出!!
}