Creating A Simple Registration Form In ASP.NET

Introduction

The example, shown below, exhibits how to create a very simple registration form in ASP.NET Web forms.



Step 1

Create a table in the database (SQL Server 2012)
  1. Create a database and name it as Login.
  2. Add the table (here table name: tbllogin)
  3. Set primary key to Id column.


Note

In this example, I set the Id to auto increment, so that the Id will be automatically generated for every new added row. To do this, select the column name Id and in the column properties set the Identity Specification to yes.



Step 2

Create new project in Visual Studio 2015
  1. Go to File-> New-> WebSite-> Visual C#->ASP.NET Empty Website-> Entry Application Name-> OK.




Step 3

Create new web form to web site
  1. Right click on Website-> Add-> Add New Item->Visual C#->Web Form->write Web form name with .aspx extension->Add





  2. RegistrationForm.aspx created ( RegistrationForm is a Web form name).

    HTML Source code of registration form is mentioned below.
    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RegistraionForm.aspx.cs" Inherits="RegistraionForm" %>  
    2.   
    3. <!DOCTYPE html>  
    4.   
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head runat="server">  
    7.     <title></title>  
    8. </head>  
    9. <body>  
    10.     <form id="form1" runat="server">  
    11.         <div>  
    12.             <table class="auto-style1">  
    13.                 <tr>  
    14.                     <td>Name :</td>  
    15.                     <td>  
    16.                         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
    17.                     </td>  
    18.   
    19.                </tr>  
    20.                 <tr>  
    21.                     <td>Password</td>  
    22.                      <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>  
    23.                 </tr>  
    24.                 <tr>  
    25.                     <td>Confirm Password</td>  
    26.                     <td>  
    27.                         <asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>  
    28.                     </td>  
    29.                 </tr>  
    30.                 <tr>  
    31.                     <td>City</td>  
    32.                     <td>  
    33.                         <asp:DropDownList ID="DropDownList1" runat="server">  
    34.                             <asp:ListItem Text="Select City" Value="select" Selected="True"></asp:ListItem>  
    35.                             <asp:ListItem Text="Bangalore" Value="Bangalore"></asp:ListItem>  
    36.                             <asp:ListItem Text="Mysore" Value="Mysore"></asp:ListItem>  
    37.                             <asp:ListItem Text="Hubli" Value="hubli"></asp:ListItem>  
    38.                         </asp:DropDownList>  
    39.                     </td>  
    40.                 </tr>  
    41.                 <tr>  
    42.                     <td>Gender</td>  
    43.                     <td>  
    44.                         <asp:RadioButtonList ID="RadioButtonList1" runat="server">  
    45.                             <asp:ListItem>Male</asp:ListItem>  
    46.                             <asp:ListItem>Female</asp:ListItem>  
    47.                         </asp:RadioButtonList>  
    48.                     </td>  
    49.                </tr>  
    50.                 <tr>  
    51.                     <td>Gmail</td>  
    52.                     <td>  
    53.                         <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>  
    54.                     </td>  
    55.                 </tr>  
    56.                 <tr>  
    57.                     <td>  
    58.                         <asp:Button ID="Button1" runat="server" Text="Button" />  
    59.                     </td>  
    60.                 </tr>  
    61.             </table>  
    62.         </div>  
    63.     </form>  
    64. </body>  
    65. </html>  
  3. HTML Source code is created following the registration form.



  4. Click Submit button. You will see the code, mentioned below. (code at the back-end)



  5. C# code is in void button click event, as shown below.

Add Namespaces, mentioned below, at the code back-end page.



Write Insert code in Button1_Click Event.



That’s it. I hope you will find this example useful.

Ebook Download
View all
Learn
View all