[英]Method not firing on textbox text change
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. 如您所见,我有
AutoPostBack="true"
和OnSelectionChanged="customDateFrom_SelectionChanged
为文本框分配的OnSelectionChanged="customDateFrom_SelectionChanged
。
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?
为什么会发生这种情况,我该如何解决?
I assume you want to handle the TextBox
' TextChanged
event instead. 我假设你想要处理
TextBox
的TextChanged
事件。 SelectionChanged
is a winforms event which doesn't exist in ASP.NET. SelectionChanged
是一个winforms事件,在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
. 当用户更改其中的文本并离开
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 (fe in Page_Load
). 不触发事件的另一个原因是如果在触发事件之前对
TextBox
进行数据绑定(在Page_Load
为fe)。 Then you should check IsPostBack
: if(!IsPostBack)DataBindTextBox();
然后你应该检查
IsPostBack
: if(!IsPostBack)DataBindTextBox();
. 。
You should handle the TextBox.TextChanged Event .. 你应该处理TextBox.TextChanged事件 ..
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 请参阅: Asp.Net文本框TextChanged事件未触发
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.