I have a textbox with a calander extender attached:
<asp:TextBox ID="customDateTo" runat="server" AutoPostBack="true" OnSelectionChanged="customDateFrom_SelectionChanged"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="toCalendarExtender" TargetControlID="customDateTo" runat="server"></ajaxToolkit:CalendarExtender>
As you see I have AutoPostBack="true" and OnSelectionChanged="customDateFrom_SelectionChanged assigned for the textbox.
However nothing is responding in my method:
protected void customDateFrom_SelectionChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Do Something");
}
When I change the text I do get a postback but nothing within the method is executing. Why is this happening and how do I fix it?
For a TextBox, I think it should be;
OnTextChanged="customDateFrom_SelectionChanged"
Not
OnSelectionChanged="customDateFrom_SelectionChanged"
I assume you want to handle the TextBox' TextChanged event instead. SelectionChanged is a winforms event which doesn't exist in ASP.NET.
<asp:TextBox ID="customDateTo" runat="server"
AutoPostBack="true" OnTextChanged="customDateFrom_TextChanged">
</asp:TextBox>
This event is raised when the user changes the text in it and leaves the TextBox.
protected void customDateFrom_TextChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Do Something");
}
Another reason for not triggering an event is if you databind the TextBox before the event is triggered (f.e. in Page_Load). Then you should check IsPostBack: if(!IsPostBack)DataBindTextBox();.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With