public partial class FrmNewUser : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=SONIA-B408A4159\\SQLEXPRESS;Initial catalog=sonia;Integrated Security=true");
string query;
SqlCommand cmd;
public string name="Code";
protected void Page_Load(object sender, EventArgs e)
{
btnRegister.Attributes.Add("onclick", "javascript:return LenofPassword()");
}
protected void btnRegister_Click(object sender, EventArgs e)
{
try
{
query = "Insert into Newuser values(@UserName,@Password,@FullName)";
cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@FullName", txtFullname.Text);
conn.Open();
cmd.ExecuteNonQuery ();
conn.Close ();
}
catch(Exception ex)
{
lblErrors.Text =ex.Message.ToString();
}
}
<title>New User Registration</title>
<script type ="text/javascript" language ="javascript" >
function LenofPassword()
{
var Password=document.getElementById("txtPassword");
if(Password.value == "")
{
alert("Password should not be empty");
Password.focus();
return false;
}
if (Password.value.length <= 6 )
{
alert("Password length should be greater than 6");
Password.focus();
return false;
}
var ConfirmPass=document.getElementById("txtConfirmPass");
if(ConfirmPass.value == "")
{
alert("Confirm Password should not be empty");
ConfirmPass.focus();
return false;
}
if( Password.value != ConfirmPass.value)
{
alert(" Password & Confirm Password do not match");
return false;
}
}
How Can i Check in JS Function that mine UserName already exists in database or not...