Reputation: 7532
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?
Upvotes: 2
Views: 10635
Reputation: 460038
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();
.
Upvotes: 3
Reputation: 18290
You should handle the TextBox.TextChanged Event..
example:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged">
// server side event:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(TextBox1.Text);
}
Refer: Asp.Net textbox TextChanged event is not firing
Upvotes: 1