问题描述
我现在有一个自定义文本框,它实现了大多数基本实现正常的文本框的了,这样做是这样的:
I currently have a custom text box, it implements majority of the base implementations a normal text box has, by doing something like:
public string Text
{
get { return customTextBox.Text; }
set { customTextBox.Text = value; }
}
我现在要实现自定义事件处理程序上的文字改为得到回发。我目前在做以下这是正确的,如果没有,那么我应该如何去这样的:
I now want to implement a custom event handler to get a postback on text changed. I currently am doing the following is this correct if not then how should I go about this:
private static readonly object EventCustomTextChanged = new Object();
public event EventHandler TextChanged
{
add
{
Events.AddHandler(EventCustomTextChanged, value);
}
remove
{
Events.RemoveHandler(EventCustomTextChanged, value);
}
}
本实施来源于:的
在有人说你为什么不使用一个多数民众赞成在已经存在,我会告诉你,这不是implented,因为这是一个自定义的用户控件。我想实现它。
Before someone says why don't you use the one thats already there, I will tell you it's not implented because this is a custom user control. I am trying to implement it.
在先进的感谢!
推荐答案
这是做它的方式:
public event EventHandler TextChanged
{
add { customTextBox.TextChanged += value; }
remove { customTextBox.TextChanged -= value; }
}
假设 customTextBox
是 System.Web.UI.WebControls.TextBox
控制。
这篇关于自定义文本框添加自定义OnTextChange事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!