为什么一个asp.net OnTextChanged不工作 [英] Why is an asp.net OnTextChanged not working

查看:206
本文介绍了为什么一个asp.net OnTextChanged不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是ASP.NET更新面板使用上框TextChanged为文本框来获取用户信息,这里是我的code:

 < ASP:的UpdatePanel =服务器ID =上一条ChildrenAsTriggers =真>
<&的ContentTemplate GT;
    < ASP:文本框=服务器ID =表示loginEmail文本=电子邮件
        的CssClass =文本框OnTextChanged =用户信息的AutoPostBack =真>< / ASP:文本框>
< /&的ContentTemplate GT;
<&触发器GT;
    < ASP:AsyncPostBackTrigger控件ID =表示loginEmail事件名称=框TextChanged/>
< /触发器>
< / ASP:的UpdatePanel>

和背后的code:

 字符串的URL,emailInfo;
emailInfo = loginEmail.Text;
URL = Membership.GetUserNameByEmail(emailInfo);emailText.InnerText =电子邮件:+ emailInfo;
urlText.InnerText =网站:http://www.Elwazefa.com/User/+网址;

的code不会火框TextChanged ,但该宏将会,
在ButtonClick或pageLoad的。

这是什么问题?

使用ASP.NET 4.0


解决方案

 < ASP:文本框的AutoPostBack =真OnTextChanged =thingId_TextChangedID =thingId=服务器>< / ASP:文本框>

的AutoPostBack 上文本框将触发后回来时,焦点从文本框丢失。 框TextChanged 活动将在任何后续回哨所发射(可能是由于按钮单击或文本框焦点变化)。所以,你需要做出一定


  1. 文本后发生了变化,你搬出文本框

  2. 不管控制,你是改变是更新面板的一部分(可以是不同的更新面板)。如果没有那么任何更新面板的一部分,这些更改将不会得到反映在客户端。

我的猜测是,你很可能从2痛苦。您可以使用工具,如提琴手(或萤火虫的Firefox浏览器),以检查是否浏览器被触发AJAX(XHR)请求时,焦点从文本框丢失。

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>

and the code behind:

string url, emailInfo;
emailInfo = loginEmail.Text;
url = Membership.GetUserNameByEmail(emailInfo);

emailText.InnerText = "Email: " + emailInfo;
urlText.InnerText = "Webiste: http://www.Elwazefa.com/User/" + url ; 

the code wont fire on textchanged but it wil, on ButtonClick or PageLoad.

What is the problem?

Using ASP.NET 4.0

解决方案

<asp:TextBox AutoPostBack="true" OnTextChanged="thingId_TextChanged" ID="thingId" runat="server"></asp:TextBox>

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

  1. After text is changed, you are moving out of text-box
  2. Whatever controls that you are change are part of update-panel (can be different update panel). If there are not part of any update panel then those changes won't get reflected on client side.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆