You try this for availability
Aspx page
<body>
<form id="form1" runat="server">
<div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="*" Style="z-index: 100; left: 783px; position: absolute; top: 104px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="*" Style="z-index: 101; left: 785px; position: absolute; top: 157px"></asp:RequiredFieldValidator>
<asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 453px; position: absolute;
top: 97px" Text="Username:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" Style="z-index: 103;
left: 554px; position: absolute; top: 96px" TabIndex="1"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Style="z-index: 104; left: 479px; position: absolute;
top: 156px" Text="Name:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Style="z-index: 105; left: 553px; position: absolute;
top: 155px" TabIndex="2"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Style="z-index: 106; left: 842px; position: absolute;
top: 121px"></asp:Label>
<asp:Button ID="Button1" runat="server" Style="z-index: 107; left: 602px; position: absolute;
top: 219px" Text="Button" Width="54px" />
<div id="checkusername" runat="server" Visible="false">
<asp:Label ID="lblStatus" runat="server" style="z-index: 108; left: 763px; position: absolute; top: 75px"></asp:Label>
<asp:Image ID="imgstatus" runat="server" Width="20px" Height="20px" style="z-index: 109; left: 765px; position: absolute; top: 100px"/>
</div>
<asp:Image ID="Image1" runat="server" style="z-index: 111; left: 382px; position: absolute; top: 133px" ImageUrl="~/Images/LoadingImage.gif" Visible="False" />
</div>
</form>
</body>
</html>
Code behind...
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text))
{
SqlConnection con;
SqlCommand cmd;
string constr = ConfigurationManager.ConnectionStrings["SomeDataBase"].ToString();
con = new SqlConnection(constr);
cmd = new SqlCommand("Select * from Thi where Username=@Username", con);
con.Open();
cmd.Parameters.AddWithValue("@Username", TextBox1.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Images/NotAvailable.jpg";
Label3.Text = "UserName Already Taken";
if (Label3.Text == "UserName Already Taken")
{
TextBox1.Text = " ";
}
System.Threading.Thread.Sleep(2000);
}
else
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Images/Icon_Available.gif";
Label3.Text = "UserName Available";
System.Threading.Thread.Sleep(1000);
con.Close();
}
}
else
{
checkusername.Visible = false;
}
}
I hope its help you... Happy coding.