Register.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1Register.aspx.cs" Inherits="Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 198px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td colspan="2"><center>SIGNUP FORM</center></td>
</tr>
<tr>
<td class="auto-style2">FIRST NAME</td>
<td>
<asp:TextBox ID="FirstNameTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ErrorMessage="Please Enter First Name" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="FirstNameTextBox">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">LAST NAME</td>
<td>
<asp:TextBox ID="LastNameTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic" ErrorMessage="Please Enter Last Name" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="LastNameTextBox">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">GENDER</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="167px">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue="Select" ID="RequiredFieldValidator3" runat="server" Display="Dynamic" ErrorMessage="Please Select a Gender" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="DropDownList1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">EMAIL</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Display="Dynamic" ErrorMessage="Please Enter Email" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="EmailTextBox">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="EmailTextBox" Display="Dynamic" ErrorMessage="Please Write Valid Email" ForeColor="#FF3300" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">ADDRESS</td>
<td>
<asp:TextBox ID="AddressTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" Display="Dynamic" ErrorMessage="Please Enter Address" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="AddressTextBox">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">USERNAME</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" Display="Dynamic" ErrorMessage="Please Enter UserName" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="UserNameTextBox">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">PASSWORD</td>
<td>
<asp:TextBox ID="PasswordTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" Display="Dynamic" ErrorMessage="Please Enter Password" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="PasswordTextBox">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="PasswordTextBox" Display="Dynamic" ErrorMessage="Please Enter a Strong Password" ForeColor="#FF3300" SetFocusOnError="True" ValidationExpression="(?=^.{8,}$)((?=.*\d)|(?=.*\w+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style2">CONFORM PASSWORD</td>
<td>
<asp:TextBox ID="ConfirmPAsswordTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" Display="Dynamic" ErrorMessage="Please Enter Confirm Password" ForeColor="#FF3300" SetFocusOnError="True" ControlToValidate="ConfirmPAsswordTextBox">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="PasswordTextBox" ControlToValidate="ConfirmPAsswordTextBox" ErrorMessage="Password is not Identical" ForeColor="Red" SetFocusOnError="True">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" Text="SINUP" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<a href="Login.aspx">Go To Login Form</a>
</td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" BackColor="#999999" Font-Size="Larger" ForeColor="#FF3300" />
</div>
</form>
</body>
</html>
Register.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Register : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(cs);
string query = "insert into signup values(@fname,@lname,@gender,@email,@address,@username,@password)";
SqlCommand cmd = new SqlCommand(query,con);
cmd.Parameters.AddWithValue("@fname", FirstNameTextBox.Text);//Parameter Passing in this statement
cmd.Parameters.AddWithValue("@lname", LastNameTextBox.Text);
cmd.Parameters.AddWithValue("@gender", DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("@email", EmailTextBox.Text);
cmd.Parameters.AddWithValue("@address",AddressTextBox.Text);
cmd.Parameters.AddWithValue("@username", UserNameTextBox.Text);
cmd.Parameters.AddWithValue("@password", PasswordTextBox.Text);
con.Open();
int a = cmd.ExecuteNonQuery();
if(a>0)
{
ClientScript.RegisterStartupScript(typeof(Page), "script", "alert('Signup Successfull....Username is:"+UserNameTextBox.Text+" and Password is:"+PasswordTextBox.Text+"');",true);
Clearcontrols();
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "scripts", "<script>alert('Signup Failed !!')</script>");
}
cmd.ExecuteNonQuery();
con.Close();
}
//It can clear textbox value after pressing submit button
void Clearcontrols()
{
FirstNameTextBox.Text = LastNameTextBox.Text = EmailTextBox.Text = AddressTextBox.Text = UserNameTextBox.Text = PasswordTextBox.Text = ConfirmPAsswordTextBox.Text = "";
DropDownList1.ClearSelection();
}
}
0 Comments