我的代码 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标签不显示。 请帮我解决这个问题?
答案 0 :(得分:0)
如果禁用AutoPostBack,您需要在更新面板中进行其他控制以将异步回发提升到服务器
例如,在文本框后面放置一个按钮。