Wednesday, February 9, 2011

How to set check availability button in registration form using aspnet

First,open the visual studio 2008

Next,select one Asp Web Application and click ok

Next download one Gif image for to show loading

Next,Open the design page of Default.aspx


Next,Drag and drop one UpdatePanel,one textbox from the toolbox

Next,In that Updatepanel Drag and drop one Link button and label

Next,add one image

Next,Come to the Source page of default.aspx page

Next,code will be look like this


<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <ContentTemplate>              
      <div id="divImage" style="display:none">
       <asp:Image ID="img1" runat="server" ImageUrl="~/images/ajax-loader.gif" />
                     Processing...
                </div>              
                <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>
        </asp:UpdatePanel>


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());
        con.Open();
        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;        
        }
        else
        {
            if (txt_uname.Text == "")
            {
                lbl_msg1.Text = "Please Enter the Username";
            }
            else
            {
                lbl_msg1.Text = "Available";
            }
        }
    }

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

developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , ,

5 Comments:

At April 25, 2011 at 7:53 PM , Anonymous UR Friend said...

Hey its very simple..thanks

 
At April 25, 2011 at 7:53 PM , Anonymous Anonymous said...

very useful tip

 
At May 3, 2011 at 9:29 AM , Anonymous Anonymous said...

Thanks for sharing

 
At June 28, 2011 at 10:17 AM , Anonymous UR Friend said...

Hey its very simple..thanks

 
At August 20, 2013 at 2:13 PM , Anonymous Anonymous said...

great post

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home