Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Thursday, 31 March 2016

Registration Page In Asp.Net C#

 No comments   

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.


  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write