[英]Method not firing on textbox text change
我有一个带有压延扩展器的文本框:
<asp:TextBox ID="customDateTo" runat="server" AutoPostBack="true" OnSelectionChanged="customDateFrom_SelectionChanged"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="toCalendarExtender" TargetControlID="customDateTo" runat="server"></ajaxToolkit:CalendarExtender>
如您所见,我有AutoPostBack="true"
和OnSelectionChanged="customDateFrom_SelectionChanged
为文本框分配的OnSelectionChanged="customDateFrom_SelectionChanged
。
但是我的方法没有响应:
protected void customDateFrom_SelectionChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Do Something");
}
当我更改文本时,我确实得到了回发,但方法中没有任何内容正在执行。 为什么会发生这种情况,我该如何解决?
对于TextBox ,我认为它应该是;
OnTextChanged="customDateFrom_SelectionChanged"
不
OnSelectionChanged="customDateFrom_SelectionChanged"
我假设你想要处理TextBox
的TextChanged
事件。 SelectionChanged
是一个winforms事件,在ASP.NET中不存在。
<asp:TextBox ID="customDateTo" runat="server"
AutoPostBack="true" OnTextChanged="customDateFrom_TextChanged">
</asp:TextBox>
当用户更改其中的文本并离开TextBox
时,将引发此事件。
protected void customDateFrom_TextChanged(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Do Something");
}
不触发事件的另一个原因是如果在触发事件之前对TextBox
进行数据绑定(在Page_Load
为fe)。 然后你应该检查IsPostBack
: if(!IsPostBack)DataBindTextBox();
。
你应该处理TextBox.TextChanged事件 ..
例:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged">
//服务器端事件:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Label1.Text = Server.HtmlEncode(TextBox1.Text);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.