Wednesday, 12 June 2013

check availability of username

How to set check availability button in registration form using aspnet

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
      <div id="divImage" style="display:none">
       <asp:Image ID="img1" runat="server" ImageUrl="~/images/ajax-loader.gif" />
                <br />          
                    <asp:LinkButton ID="lb_checkavail" runat="server" CausesValidation="False"
                        Font-Underline="False" onClick="lb_checkavail_Click"
                    style="font-weight: 700" ForeColor="#00CCFF">Check Availability</asp:LinkButton><br />
                    <asp:Label ID="lbl_msg1" runat="server" Font-Bold="True"
                    Font-Names="Verdana" ForeColor="#FF9933"></asp:Label></ContentTemplate>

Now,come to the code page of Default.aspx.cs

write the following code for the link button

protected void lb_checkavail_Click(object sender, EventArgs e)
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["SAMPLE_2"].ToString());
        com = new SqlCommand("select * from Users where Username='"+txt_uname.Text+"'",con);
        dr = com.ExecuteReader();
        if (dr.Read())
                lbl_msg1.Text = "Not Availble";
                this.lbl_msg1.ForeColor = Color.DarkGreen;        
            if (txt_uname.Text == "")
                lbl_msg1.Text = "Please Enter the Username";
                lbl_msg1.Text = "Available";

Finally execute the page.....Thats it...

No comments:

Post a Comment