My code
Asp block:
———-
<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>
The code behind part:
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";
}
}
so my problem here is that once i enter mailid into textbox the validator is still there it is not leaving. If i remove autopostback property my validator is working fine but my ajax label is not displayed.
Please help me with this query?
In case when AutoPostBack is disabled, you need other control inside your update panel for raise async postback to server
Place a button after your textbox, for example.