Registration Page in Asp.Net Using Stored Procedure
For to creating a Simple Registration Page in Asp.Net you need to create database first for to better understanding about the fields used in design.
So in SQL use following queries
// create database DbTest………………………
Create database DbTest
Use DbTest
// create table UserInfo database DbTest………………………
cretae table UserInfo (fname nvarchar(50) ,lname nvarchar(50) , DOB date, Gender nvarchar(10) ,Email nvarchar(100), Address nvarchar(250), Phone int, Password nvarchar(50))
Stored Procedure for UserInfo Table
create proc sp_UserInfo( @fname varchar(50), @lname varchar(50),@dob datetime,@gen varchar(50),@email nvarchar(250), @address nvarchar(250),
@phone int, @password varchar(50))
as
begin
insert into UserInfo (fname,lname,DOB, Gender ,Email ,Address ,Phone, Password) values(@fname ,@lname ,@dob ,@gen, @email ,@address,@phone , @password)
end
Thats all from Database end. Now we switch to Visual Studio for design our Page.
Create New Web Form and named it as per your requirment or need .
On .aspx page write the following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../Scripts/jquery-1.10.2.js"></script>
<link href="../Scripts/jquery-ui-themes-smoothness.css" rel="stylesheet" />
<script src="../Scripts/jquery-ui-1.10.4.js"></script>
<link href="../Scripts/Demostyle.css" rel="stylesheet" />
<script>
$(function () {
$(".datepicker").datepicker();
});
</script>
<style type="text/css">
.text{
width:200px;
height:21px;
}
.tdStyle
{
font-size:medium;
font-style:normal;
font-family:Arial;
}
.tdAlign {
text-align: right;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%; align-content:center">
<tr ><th colspan="2" style="font-size:medium;" >User registration</th></tr>
<tr>
<td class="tdAlign tdStyle">First Name</td>
<td><asp:TextBox ID="txtfname" runat="server" placeholder="First Name" CssClass="text"> </asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Last name</td>
<td><asp:TextBox ID="txtlname" runat="server" placeholder="Last Name" CssClass="text"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">DOB</td>
<td><asp:TextBox ID="txtDob" runat="server" class="datepicker" placeholder="DOB" Width="200px"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Gender</td>
<td><asp:RadioButtonList ID="rblgender" runat="server" Width="200px" RepeatDirection="Horizontal" CssClass="text" Font-Size="Medium" >
<asp:ListItem >Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Email</td>
<td><asp:TextBox ID="txtemail" runat="server" placeholder="Email" CssClass="text"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Password</td>
<td><asp:TextBox ID="txtpassword" runat="server" placeholder="Password" TextMode="Password" CssClass="text"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Phone</td>
<td><asp:TextBox ID="txtphone" runat="server" placeholder="Phone" CssClass="text"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle">Address</td>
<td><asp:TextBox ID="txtaddress" runat="server" TextMode="MultiLine" Rows="3" placeholder="Address" CssClass="text"></asp:TextBox></td>
</tr>
<tr>
<td class="tdAlign tdStyle"> </td>
<td> <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
As you seen above code Script is used for DatePicker of Jquery and its library files refrenced under Head section .Style Sheet were used for make page looks good.
Now in Code-Behind window write functionality for saving information entered by the User.
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("spempdetail", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue.FName =
txtfname.Text;
cmd.Parameters.AddWithValue.Lname
= txtlname.Text;
cmd.Parameters.AddWithValue.DOB =
txtDob.Text;
cmd.Parameters.AddWithValue.Gender
= rblgender.SelectedValue;
cmd.Parameters.AddWithValue.Email
= txtemail.Text;
cmd.Parameters.AddWithValue.Pasword = txtpassword.Text;
cmd.Parameters.AddWithValue.Phone
= Convert.ToInt32(txtphone.Text);
cmd.Parameters.AddWithValue.Address = txtaddress.Text; ;
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
con.Close();
Response.Write("<script language=javascript>alert('Data Saved
Succesfully');</script>");
btnsave.Visible = true;}
else
{
Response.Write("<script language=javascript>alert('Data not
Inserted');</script>");
con.Close();
}
}
}
catch(Exception ex)
{
Response.Write("<script language=javascript>alert('Something
went wrong');</script>");
}
}
Now run the application and enjoy.
0 comments:
Post a Comment