0

我的代码 Asp 块:

----------

            <ContentTemplate>
            <asp:Label runat="server" ID="lblHelloWorld" Text="label" />
            <br />
                <asp:TextBox ID="TextBox2"  AutoPostBack ="true" OnTextChanged="emailavail"  runat="server" ></asp:TextBox>
                <br />
            </ContentTemplate>
            </asp:UpdatePanel>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ControlToValidate="TextBox2" ErrorMessage="Emailid cannot be left blank" Display="Dynamic"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Display="Dynamic"   
                ControlToValidate="TextBox2" ErrorMessage="Enter correct mailid" 
                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

部分背后的代码:


     protected void emailavail(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection();
    con.ConnectionString = "Data Source=DB-SERVER-PC\\NET3USER;Initial Catalog=prakash;User Id=sa;Password=strongsa;";
    con.Open();
    SqlCommand com = new SqlCommand("Select Emailid from details1 where Emailid=@email", con);
    com.Parameters.AddWithValue("@email", TextBox2.Text);

    SqlDataReader dr;
    dr = com.ExecuteReader();
    if (dr.Read() == true)
    {
        lblHelloWorld.Text = "Email not available";
    }
    else
    {
        lblHelloWorld.Text = "Email available"; 
    }
}

所以我的问题是,一旦我在文本框中输入mailid,验证器仍然在那里,它不会离开。如果我删除 autopostback 属性,我的验证器工作正常,但不显示我的 ajax 标签。请帮我解决这个问题?

4

1 回答 1

0

如果禁用 AutoPostBack,您需要在更新面板中进行其他控制以将异步回发到服务器

例如,在文本框之后放置一个按钮。

于 2012-07-31T15:33:34.597 回答