I have an Asp.Net solution with an MasterPage and a ContentPage. I put the ContentPage inside an UpdatePanel, so the events will not refresh the entire page.

In the ContentPage I have a TextBox with an "OnTextChanged" event that works just fine.

The problem is that I wan't to use the JQuery MaskedInput plugin in that same TextBox and it seems to stop working. An button click (for example) fires the event, but the TextBox doesn't postback by itself, even though I've set the "AutoPostBack" as "true".

This is my function that sets the mask:

function pageLoad() { $('#txtCpf').mask('999.999.999-99'); }

This is my TextBox:

<asp:TextBox runat="server" ID="txtCpf" AutoPostBack="true" CssClass="txtCpf" MaxLength="14" CausesValidation="True" OnTextChanged="txtCpf_TextChanged" TabIndex="3"></asp:TextBox>

And this is the code-behind:

protected void txtCpf_TextChanged(object sender, EventArgs e)
    {
        con = new ClasseConexao();
        ds = new DataSet();
        ds = con.conectar_consultar("EXEC usp_VerificarCliente '" + txtCpf.Text + "', ''");
        string mensagem = ds.Tables[0].Rows[0][0].ToString();

        if (mensagem != "0")
        {
            pnlMensagemCpf.Visible = true;
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Foco", "$(function cpf(){$('#txtCpf').focus()})", true);
        }
        else
        {
            pnlMensagemCpf.Visible = false;
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Foco", "$(function rg(){$('#txtRg').focus()})", true);
        }
    }

This code works without the mask, but not along with the plugin. And the mask works, but doesn't postback. So... how can I use the JQuery's plugin and still AutoPostBack my TextBox?

Related posts

Recent Viewed