Adding custom OnTextChange event handler on custom TextBox
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);
}
}
This implementation comes from: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.ontextchanged.aspx
Before someone says why don't you us开发者_JAVA百科e 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.
Thanks in Advanced!
This is the way to do it:
public event EventHandler TextChanged
{
add { customTextBox.TextChanged += value; }
remove { customTextBox.TextChanged -= value; }
}
Assuming that customTextBox
is the System.Web.UI.WebControls.TextBox
control.
精彩评论