Introduction
The example shown below exhibits how to create a very simple registration form in ASP.NET Web forms.
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.
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.
2. Create a new project in Visual Studio 2015
- Go to File-> New-> WebSite-> Visual C#->ASP.NET Empty Website-> Entry Application Name-> OK.
3. Create a new web form for the website
- 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).
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>
- HTML Source code is created following the registration form.
- Click the Submit button. You will see the code mentioned below. (code at the back end).
- C# code is in the 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.