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.

WebForm

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.

CreateTable

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

Properties

2. Create a new project in Visual Studio 2015

  1. Go to File-> New-> WebSite-> Visual C#->ASP.NET Empty Website-> Entry Application Name-> OK.

3. Create a new web form for the website

  1. Right-click on Website-> Add-> Add New Item->Visual C#->Web Form->write Web form name with .aspx extension->Add.
    AddNewWebForm
    FormProp
  2. RegistrationForm.aspx created ( RegistrationForm is a Web form name).
    The HTML Source code of the registration form is mentioned below.
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RegistraionForm.aspx.cs" Inherits="RegistraionForm" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <p>
                <table class="auto-style1">
                    <tr>
                        <td>Name :</td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td>
                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>Confirm Password</td>
                        <td>
                            <asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>City</td>
                        <td>
                            <asp:DropDownList ID="DropDownList1" runat="server">
                                <asp:ListItem Text="Select City" Value="select" Selected="True"></asp:ListItem>
                                <asp:ListItem Text="Bangalore" Value="Bangalore"></asp:ListItem>
                                <asp:ListItem Text="Mysore" Value="Mysore"></asp:ListItem>
                                <asp:ListItem Text="Hubli" Value="hubli"></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>Gender</td>
                        <td>
                            <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                                <asp:ListItem>Male</asp:ListItem>
                                <asp:ListItem>Female</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                    </tr>
                    <tr>
                        <td>Gmail</td>
                        <td>
                            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="Button1" runat="server" Text="Button" />
                        </td>
                    </tr>
                </table>
            </p>
        </form>
    </body>
    </html>
    

     

  3. HTML Source code is created following the registration form.
    SourceCode
  4. Click the Submit button. You will see the code mentioned below. (code at the back end).
    RegForm
  5. C# code is in the void button click event, as shown below.

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

Backend

Write Insert code in Button1_Click Event.

BtnProp

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