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)
- Create a database and name it as Login.
- Add the table (here table name: tbllogin)
- Set primary key to Id column.
NoteIn 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
- Go to File-> New-> WebSite-> Visual C#->ASP.NET Empty Website-> Entry Application Name-> OK.
Step 3
Create new web form to web site
- Right click on Website-> Add-> Add New Item->Visual C#->Web Form->write Web form name with .aspx extension->Add
- RegistrationForm.aspx created ( RegistrationForm is a Web form name).
HTML Source code of 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">
- <div>
- <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>
- </div>
- </form>
- </body>
- </html>
- HTML Source code is created following the registration form.
- Click Submit button. You will see the code, mentioned below. (code at the back-end)
- 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.