Skip to main content

Create a simple registration form in ASP.Net with C#

In this article we will how to create or design a simple registration form in ASP.Net with the help of C sharp and store the entries in SQL Server database.


You will need following software's to accomplish this:
  1. Visual Studio 2010
  2. SQL Server 2008

Follow the steps below to make it:

Step 1: First open your visual studio 2010 -> File -> New -> Web site -> ASP.NET Empty Web site -> click OK. (Make sure to select Visual C# from installed template and you can give the name to the website.)

Step 2: Now in Solution Explorer -> Add New Item -> Web Form -> click on Add.

Step 3: Now make the basic html table in the source section of empty form and insert the fields like - 


registration form in ASP.Net with C sharp

Use the Text boxes for each field, Label for username to see the availability, Buttons from the Toolbox section. Set unique ID for these tools to avoid confusion.

To make the reset button add following line in the source code near the submit button.
 <input id="Reset1" type="reset" value="Reset" onclick="return Reset1_onclick()" />  

Step 4: To setup SQL Server connectivity Go to -> Server explorer -> Right click on Data Connections -> Add connection -> Select Data Source Microsoft SQL Server(SqlClient) -> Select server name -> Select or enter the name of database -> Test the connection -> Click Ok.
 (To select the data source Go to -> Server explorer -> Right click on newly added database -> Properties -> Copy the connection string)

Step 5: Now double click on Submit button to write C# code and copy paste the following code.

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Data.Sql;  
 using System.Data.SqlClient;  
 using System.Drawing;  
 public partial class registration : System.Web.UI.Page  
 {  
   protected void Page_Load(object sender, EventArgs e)  
   {  
   }  
   SqlConnection connection = new SqlConnection("Data Source=*;Initial Catalog=PlacementCellProject;Integrated Security=True");  //Copy paste your connection string from newly created database.
   SqlCommand cmd;  
   SqlDataReader dr;  
   protected void SubmitButton_Click(object sender, EventArgs e)  
   {  
     connection.Open();  
     cmd = new SqlCommand("insert into StudentRegistration values('"+txtFname.Text+"', '"+txtMname.Text+"', '"+txtLname.Text+"', '"+txtUname.Text+"', '"+txtEnno.Text+"', '"+txtEmail.Text+"', '"+txtPassword.Text+"', '"+txtRepassword.Text+"', '"+txtMob.Text+"')", connection);  
     cmd.Parameters.AddWithValue("@Username", txtUname.Text);  
     dr = cmd.ExecuteReader();  
     if (dr.HasRows)  
     {  
       MsgLabel.Text = "Username is already exist!";  
       this.MsgLabel.ForeColor = Color.Red;  
     }  
     else  
     {  
       MsgLabel.Text = "Username is available!";  
       this.MsgLabel.ForeColor = Color.Green;  
     }  
   }  
 }  

Html code of form:
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="registration.aspx.cs" Inherits="registration" %>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
   <title></title>  
   <style type="text/css">  
     .style1  
     {  
       font-size: xx-large;  
       color: #FF0000;  
     }  
   </style>  
 </head>  
 <body>  
   <form id="form1" runat="server">  
   <div>  
     <table>  
       <tr>  
         <td colspan="3" class="style1">  
           <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter Details </strong>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>First Name*</strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtFname" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Middle Name* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtMname" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Last Name* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtLname" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Username* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtUname" runat="server"></asp:TextBox>  
         </td>  
         <td>  
           <asp:Label ID="MsgLabel" runat="server"></asp:Label>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Enrollment No.*</strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtEnno" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Email* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Password* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Re-type Password* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtRepassword" runat="server" TextMode="Password"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td>  
           <strong>Mobile No* </strong>  
         </td>  
         <td>  
           <asp:TextBox ID="txtMob" runat="server"></asp:TextBox>  
         </td>  
         <td>  
         </td>  
       </tr>  
       <tr>  
         <td colspan="3">  
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
           <asp:Button ID="SubmitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click" />  
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
           <input id="Reset1" type="reset" value="Reset" onclick="return Reset1_onclick()" />  
         </td>  
       </tr>  
     </table>  
   </div>  
   </form>  
 </body>  
 </html>  

Step 6: Now hit on debug button to test the code. To check whether the entries has been successfully stored or not check the table of your database in SQL Server.


I hope this tutorial helpful for you! If you have any difficulty regarding this post your queries below in comment section. :)

Comments

Popular posts from this blog

How to use XBOX 360 Controller Emulator (x360ce) for NFS Rivals and other PC Games

A s we know many of PC Games only supports XBOX 360 controller officially to play the game. If you have local pc gamepad controller then it might not work well with some pc games. So you have to use application called x360ce i.e XBOX 360 Controller Emulator. It emulate your non xbox 360 controller i.e gamepad as xbox 360 controller i.e. force non xbox 360 controller to work as xbox 360 controller. So in this article we will see how to configure x360ce to work with NFS Rivals. HOW TO USE XBOX 360 CONTROLLER EMULATOR (x360ce) 1) Download x360ce and extract xbox360ce.exe in folder where you have installed NFS Rivals. 2) Now open the x360ce.exe from NFS Rivals folder. 3) You will see message like-  'x360ce.ini' was not found. Click on Yes to create ini file. 4) After that you will see the message- 'xinput1_3.dll' was not found. Click on Yes to create it. 5) Next it will detect your controller device. Now select 'Browse my computer for settings...

How to get Android Lollipop Launcher on your Android 4.4 KitKat

As we know Android 5.0 Lollipop is already comes up for Nexus devices and it has got new launcher interfaces. In this article we are going to see how to get Android Lollipop Launcher on your Android device but before going further make sure you are using Android 4.4 KitKat to make this work. This trick has been tested on my Asus Zenfone 5 running on KitKat 4.4.2. So let us start. HOW TO GET ANDROID LOLLIPOP LAUNCHER ON YOU ANDROID KITKAT Download latest Google Play Store (Version 5.0.38). If you have already you can skip this step. You can download it from this link- http://goo.gl/oFn0IW Now download latest version of Google Now Launcher (1.1.1.1516623). If you have already, you can also skip this step. Download it from Play Store- http://goo.gl/4VhGkd Now you have to download Google Search (4.0.26.1499465.arm) designed for Android Lollipop from this link- http://goo.gl/Z9aVou If you got any error like "Unfortunately, Google Search has stopped" then do t...

How to download Scribd books in PDF for free

You guys have definitely heard about Scribd. It is a digital library, featuring an electronic book monthly subscription service. They have different monthly plans for reading and downloading an electronic book in various formats such as PDF, DOC, TXT, etc. If you have credit card or Paypal account then you can easily get monthly subscription. You have to pay once for a month, then you can read and download any book in that duration after that you have to extend your subscription. If you don't have a credit card and want to download ebook then we are going to see how to do it for free. HOW TO DOWNLOAD SCRIBD BOOKS FOR FREE 1. Go to Scribd. 2. Search or Brows the electronic book that you want to download. 3. Now copy the URL of that electronic book. Now click on Download. 4. You can login with your Facebook account or you can sign up for free. I'm going to login Scribd with my facebook account. 5. Now you will be redirected to monthly subscription page...