What is the Registration Page in ASP.net?
Registration Page in ASP.net – The Registration Page is an excellent way to gather information about your event attendees before they arrive.
A registration page usually has several fields for registrants to fill out with their personal information. These fields can either be required or optional.
What should be on a registration page using ASP.net?
The listed given below are the list of fields inside the registration form.
- Name
- Mobile
- Address
- Username
- Password
Registration Page In ASP.net MVC: Project Details and Technology
Project Title: | Registration Page Project In ASP.net |
---|---|
Abstract : | Registration Page In ASP.net is an excellent way to gather information about your event attendees before they arrive. |
Project Type: | Website |
Technology : | ASP.Net Visual Studio 2022 with C# Language |
Database : | SQL-Server 2021 |
To start creating this Registration Page in ASP.net make sure that you have a Microsoft Visual Studio and SQL Server installed in your computer.
How To Make Registration Page in ASP.net with Database and Example Codes: A step-by-step Guide
Time needed: 10 minutes
How To Make a Registration Page in ASP.net
- Step 1: Open SQL Server
Open SQL Server (enter the Server Name, ID and Password then click on Connect).
- Step 2: Create a new database
Create a new database (right-click on Database then select New Database).
- Step 3: Name your database
Enter “ASPCRUD” for the database name then click OK.
- Step 4: Create a new table
Create a new table (explore the CRUD database right-click on Tables then select New Table).
- Step 5: Design the table
Design the table (name the columns and set the data types as shown in the following figure).
- Step 6: Open Visual Studio
Create a New Web Application (open Visual Studio then select File -> New ->New Project).
- Step 7: Select ASP.NET Web Application
Next, select ASP.NET Web Application(.NET Framework).
- Step 8: Name your project
Next, name your project and then, click create button.
- Step 9: Select an empty project
Next, select an empty project, then click Create.
- Step 10: Add a new item
Next, right-click on your project name on the right side under Solution Explorer and click Add then New Item.
- Step 11: Select the web form
Next, select web form click add, and name your form “Contact”
- Step 12: Add reference
Next, right-click the project in the solution explorer then click Add the click reference.
- Step 13: Add mysql.data.dll
Next, add mysql.data.dll then click ok.
- Step 14: Copy the code given
Finally, copy all code given below and paste it to each designated file.
The code given below is the HTML form for registration
Here’s the code for the registration form named “Contact.aspx“
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Contact.aspx.cs" Inherits="asp.netcrud.Contact" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:HiddenField ID="hfContactID" runat="server" /> <table> <tr> <td> <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label> </td> <td colspan="2"> <asp:TextBox ID="txtName" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label2" runat="server" Text="Mobile"></asp:Label> </td> <td colspan="2"> <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label3" runat="server" Text="Adddress"></asp:Label> </td> <td colspan="2"> <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label4" runat="server" Text="User Name"></asp:Label> </td> <td colspan="2"> <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label5" runat="server" Text="Password"></asp:Label> </td> <td colspan="2"> <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox> </td> </tr> <tr> <td> </td> <td colspan="2"> <asp:Button ID="btnSave" runat="server" Text="Register" OnClick="btnSave_Click" /> </td> </tr> <tr> <td> </td> <td colspan="2"> <asp:Label ID="lblSuccessMessage" runat="server" Text="" ForeColor="Green"></asp:Label> </td> <tr> <td> </td> <td colspan="2"> <asp:Label ID="lblErrorMessage" runat="server" Text="" ForeColor="Red"></asp:Label> </td> </tr> </tr> </table> <br /> <asp:GridView ID="gvContact" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" /> <asp:BoundField DataField="Mobile" HeaderText="Mobile" /> <asp:BoundField DataField="Address" HeaderText="Address" /> <asp:BoundField DataField="Username" HeaderText="Username" /> <asp:BoundField DataField="Password" HeaderText="Password" /> </Columns> </asp:GridView> </div> </form> </body> </html>
The code given below is the back-end of the registration form
Here’s the code for the back-end of the registration form named “Contact.aspx.cs“
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace asp.netcrud { public partial class Contact : System.Web.UI.Page { SqlConnection sqlCon = new SqlConnection(@"Data Source=LAPTOP-AMM1MQ8C;Initial Catalog=ASPCRUD;Integrated Security=true;"); protected void btnClear_Click(object sender, EventArgs e) { Clear(); } public void Clear() { hfContactID.Value = ""; txtName.Text = txtMobile.Text = txtAddress.Text = txtUsername.Text = txtPassword.Text = ""; lblSuccessMessage.Text = lblErrorMessage.Text = ""; btnSave.Text = "Register"; } protected void btnSave_Click(object sender, EventArgs e) { if (sqlCon.State == ConnectionState.Closed) sqlCon.Open(); SqlCommand sqlCmd = new SqlCommand("ContactCreateOrUpdate", sqlCon); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.AddWithValue("@ConatctID", (hfContactID.Value == "" ? 0 : Convert.ToInt32(hfContactID.Value))); sqlCmd.Parameters.AddWithValue("@Name", txtName.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Mobile", txtMobile.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text.Trim()); sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Text.Trim()); sqlCmd.ExecuteNonQuery(); sqlCon.Close(); string contactID = hfContactID.Value; Clear(); if (contactID == "") lblSuccessMessage.Text = "Saved Successfully"; else lblSuccessMessage.Text = "Updated Successfully"; FillGridView(); } void FillGridView() { if (sqlCon.State == ConnectionState.Closed) sqlCon.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("ContactViewAll", sqlCon); sqlDa.SelectCommand.CommandType = CommandType.StoredProcedure; DataTable dtbl = new DataTable(); sqlDa.Fill(dtbl); sqlCon.Close(); gvContact.DataSource = dtbl; gvContact.DataBind(); } } }
Download the Source Code below!
Conclusion
Using the .Net Framework 4.7.2 and a code generation tool, we learned how to develop an ASP.NET Web application and link it to a SQL Server to execute basic Registration Forms in ASP.net tasks.
I hope you found it beneficial. Please let us know what you think in the comments area below.
Related Articles
- Registration Form Using Tkinter With Source Code
- User Registration Form In Codeigniter With Source Code
- Registration Form in HTML with JavaScript Validation
- Login And Registration System in Django With Source Code
Inquiries
If you have any questions or suggestions about How To Create a Registration Page in ASP.net with Source Code, please feel free to leave a comment below.