ASP.NET OnTextChanged无法从更新面板内部触发 [英] ASP.NET OnTextChanged not firing from inside an update panel
问题描述
我正在使用ASP.NET更新面板使用文本框上的TextChanged检索用户信息,这是我的代码:
I am using an ASP.NET update panel to retrieve user info using the on TextChanged for the textbox, here is my code:
<asp:UpdatePanel runat="server" ID="up1" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:TextBox runat="server" ID="loginEmail" Text="Email"
CssClass="textBoxes" OnTextChanged="userInfo" AutoPostBack="true"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="loginEmail" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
及其背后的代码:
string url, emailInfo;
emailInfo = loginEmail.Text;
url = Membership.GetUserNameByEmail(emailInfo);
emailText.InnerText = "Email: " + emailInfo;
urlText.InnerText = "Webiste: http://www.Elwazefa.com/User/" + url ;
代码不会在文本更改后触发,但可以, 在ButtonClick或PageLoad上.
the code wont fire on textchanged but it wil, on ButtonClick or PageLoad.
出什么问题了?
使用ASP.NET 4.0
Using ASP.NET 4.0
推荐答案
<asp:TextBox AutoPostBack="true" OnTextChanged="thingId_TextChanged" ID="thingId" runat="server"></asp:TextBox>
AutoPostBack 当焦点从文本框中丢失时,文本框将触发回发. TextChanged
事件将在任何后续回发中触发(可能是由于单击按钮或文本框焦点更改).所以你需要确定
AutoPostBack on text-box will trigger post-back when the focus is lost from the text box. TextChanged
event will be fired on any subsequent post-back (can be due to button-click or text box focus change). So you need to make certain
- 更改文本后,您将移出文本框
- 您要更改的所有控件都是更新面板的一部分(可以是其他更新面板).如果没有任何更新面板的一部分,那么这些更改将不会反映在客户端上.
我的猜测是您可能正在遭受#2的困扰.您可以使用诸如Fiddler(或FireFox上的Firebug)之类的工具来检查当文本框失去焦点时浏览器是否正在触发AJAX(XHR)请求.
My guess is you are probably suffering from #2. You can use tool such as Fiddler (or Firebug on FireFox) to check if browser is firing AJAX (XHR) request when the focus is lost from the text-box.
这篇关于ASP.NET OnTextChanged无法从更新面板内部触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!