开发者

TextBox doesn't fire TextChanged Event on IE 8, AutoPostback is true

开发者 https://www.devze.com 2023-01-02 20:57 出处:网络
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 te

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);
})
0

精彩评论

暂无评论...
验证码 换一张
取 消