Check the Username Available
Check Username Available or Already Exists in Enter Textbox Display Valid Message Using Asp.Net C#.
DEMO
HTML CODING
Check Username Available or Already Exists in Enter Textbox Display Valid Message Using Asp.Net C#.
DEMO
DOWNLOAD CODING
HTML CODING
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table><tr><td>
<asp:Label ID="Label2" runat="server" Text="Username"></asp:Label>
</td><td>
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="True"
OnTextChanged="txtUsername_TextChanged" ></asp:TextBox>
</td><td>
<asp:Label ID="Label1" runat="server" ForeColor="#CC3300" ></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>
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);
con.Open();
}
protected void txtUsername_TextChanged(object sender, EventArgs e)
{
dbcon();
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";
break;
}
else
{
Label1.Text = "Available Username";
}
}
}
}
0 comments:
Post a Comment