Check the Username Available With Database Connection in Asp.Net C#

Check the Username Available

Check Username Available or Already Exists in Enter Textbox Display Valid Message Using Asp.Net C#.

Username Check Progressbar



                          HTML CODING

<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
                        <asp:Label ID="Label2" runat="server" Text="Username"></asp:Label>
        <asp:TextBox ID="txtUsername" runat="server" AutoPostBack="True"

            OnTextChanged="txtUsername_TextChanged" ></asp:TextBox>

          <asp:Label ID="Label1" runat="server" ForeColor="#CC3300" ></asp:Label>


                                 C# CODING

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Default6 : System.Web.UI.Page
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    SqlDataReader rd;
    string query;
    protected void Page_Load(object sender, EventArgs e)

    public void dbcon()
        string connn = (System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con = new SqlConnection(connn);
    protected void txtUsername_TextChanged(object sender, EventArgs e)
        query = "select username from register";
        cmd = new SqlCommand(query, con);
        rd = cmd.ExecuteReader();
        while (rd.Read())
            Label1.Text = "";         
            if (rd["username"].ToString() == txtUsername.Text.ToString())
                Label1.Text = "Already Exists Username";
                    Label1.Text = "Available Username";


First Create New WebForm - Add the Label & Textbox Property Set AutuPostBack =True

Next - Label - Property Set Visible=True

Showing Html Coding

Next - DataBase - Table  -  Show The Existing Values

Next - Double Click - TextBox  - Add NameSpaces & DtaBase Connection

Double Click - TextBox  - Add The Coding 


Post a Comment