Related Question: Adding custom OnTextChange event handler on custom TextBox
In the related question I asked how I could expose OnTextChange in my custom textbox control and we resolved it by:
public event EventHandler TextChanged
{
add { customTextBox.TextChanged += value; }
remove { customTextBox.TextChanged -= value; }
}
I am trying use TextChanged event like this when the control is implemented:
<uc:CustomTextBox ID="customTextBox"
runat="server"
OnTextChanged="CustomTextBox_OnTextChanged">
</uc:CustomTextBox>
This never seems to hit the following when running:
protected void CustomTextBox_OnTextChanged(System.EventArgs e)
{
// Do something here
}
Or hit:
protected void CustomTextBox_OnTextChanged(object sender, EventArgs e)
{
// Do something here
}
What am I doing wrong, what am I missing out and is this the best way or common practice way to do everything I am trying to do here?
You need to set
AutoPostBack=Trueproperty of TextBox.If you are designing a web user control then simply define public property to set
True/Falsevalue ofCustomTextBoxin user control’s code-behind:If you are developing a custom web control then you can to override the
AutoPostBackproperty for the customization. If you don’t want to customizeAutoPostBackproperty then don’t override it.In case you override AutoPostBack property, please invoke the super class’s default implementation.