自定义控件的问题!!!!!!!!!!!
各位,我按照.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!"); //这里不能输出!!
}
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!"); //这里不能输出!!
}
...全文
相关推荐
QT添加自定义控件
当QTwidget的控件不满足开发者的需求的时候,如何在QT中快捷的添加自定义控件
WPF中自定义控件教程
WPF中自定义控件开发教程,我也在学习中。
自定义控件属性在属性面板中显示的问题
自定义控件属性在属性面板中显示的问题,自定义控件属性在属性面板中显示的问题
自定义控件遇到的两个小问题
自定义控件遇到的两个小问题 自定义控件 自定义属性 描述看博客:http://blog.csdn.net/qeqeqe236/article/details/8919597
C#自定义控件VS用户控件
C#中自定义控件VS用户控件大比拼 1 自定义控件与用户控件区别 WinForm中, 用户控件(User Control):继承自 UserControl,主要用于开发 Container 控件,Container控件可以添加其他Controls控件 自定义控件(Custom Control):继承自 Control,主要用于开发windows控件的最基本的类,比如 Text,Button 控件 2 要开发自己的控件的几种方法[1] 复合控件(Composite Controls):将现有的各种控件组合起来,形成一个新的控件,来满足用户的需求。 扩展控件(Extended Controls)


