I have the same thing, there are many TextBoxes with the event TextChanged set and with AutoPostback = true, and works in all browsers (Chrome, Opera, Firefox 3.6) except in IE 8, IE 6/7 I didn't test.
I don't want to put the onblur event in all my TextBoxs because there are many pages with many TextBox that use this event.
Description开发者_JAVA技巧
I'm using a masterPage,
in the aspx i have
<asp:TextBox ID="txtCnpj" runat="server" CssClass="txt" Width="200px"
onkeyup="Mascara(this,Cnpj)" onkeydown="Mascara(this,Cnpj)" MaxLength="18"
AutoPostBack="true" ValidationGroup="txtCnpj"
OnTextChanged="txtCnpj_TextChanged"></asp:TextBox>
in the aspx.cs
protected void txtCnpj_TextChanged(object sender, EventArgs e)
{
if (CredorInvestimento.GetCredorInvestimento(txtCnpj.Text) != null)
{
((TextBox)sender).Text = "";
((TextBox)sender).Focus();
rfvCnpj.ErrorMessage = "Duplicado";
Page.Validate(txtCnpj.ID);
}
else
txtNome.Focus();
}
Thanks!
ps: I really doesn't like of asp.net I spend more time fixing errors than developing new functions.
ps: sorry for my english.
ps: if i remove the onkeydown and onkeyup events the textchanged fire in IE, but i realy this events too.
You are aware that the OnTextChanged event only fires when you leave the textbox? If you want to fire the event in KeyUp, you can add a __doPostBack to the markup and remove the autopostback.
You can use this way.
<asp:TextBox ID="txtCnpj" runat="server" CssClass="txt" Width="200px"
onkeyup="Mascara(this,Cnpj); _doPostBack('txtCnpj', '');"
MaxLength="18" ValidationGroup="txtCnpj"
OnTextChanged="txtCnpj_TextChanged"></asp:TextBox>
Or you can also use
<asp:TextBox ID="txtCnpj" runat="server" CssClass="txt" Width="200px"
MaxLength="18" ValidationGroup="txtCnpj"
OnTextChanged="txtCnpj_TextChanged"></asp:TextBox>
$('[id$="txtCnpj"]').on('keypress', function () {
Mascara(this, Cnpj);
})
精彩评论