这是我的标记:
<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server" ID="txtEmail" AutoPostBack="true" OnTextChanged="txtEmail_TextChanged" />
<asp:Panel runat="server" Visible="false" ID="pnl">
<asp:TextBox runat="server" ID="txtUname" AutoPostBack="true" OnTextChanged="txtUname_TextChanged" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
这是背后的代码:
这些是后面代码中的事件处理程序:
protected void txtEmail_TextChanged(object sender, EventArgs e)
{
pnl.Visible = true;
updPnl.Update();
txtUname.Focus();
}
protected void txtUname_TextChanged(object sender, EventArgs e)
{
}
如果我在txtEmail
文本框中按Enter键,则可以在所有浏览器中正常工作,并且焦点将转移到除Chrome以外的txtUName
文本框。在调试时我发现这种情况正在发生,因为Chrome会两次发出Ajax请求。无论如何都要解决这个Chrome错误?
请注意,如果我使用Tab而不是enter,它在Chrome中也能正常工作。但是,我也需要修复Enter的这个Chrome错误。
答案 0 :(得分:1)
您可以输入关键触发帖子到表单, 你应该阻止输入的提交动作(所以输入键和tab键会有相同的行为)
你可以使用JavaScript(onkeydown)来做到这一点。
然而,我认为这里的更新面板是一种矫枉过正, 为什么不在客户端只使用JavaScript?
$("#txtEmail").change(function() {
var email = $(this).val();
// now you can do whatever you want with the value.
});