In this tutorial, I am going to explain about "asp.net registration form" using the SQL Server database. Actually, if you are a beginner in asp.net Technology might be you are thinking that the registration form is not easy to create. But don't worry if you follow the given step, it will be very easy to create the asp.net form.
Here you will see 2 Phases during the asp.net web form creation. First, Database where your query logic gets placed. Second(Web Form), In this phase you will see two parts of a web form (.cs and .aspx). Cs page is a server-side page where our C# code and logic are written and .aspx is a client-side page, on the client-side page our validation and design are implemented.
In this tutorial, we will also implement client-side validation with the asp.net registration form.
Step to implement a registration form
Back-end process
1. Create one table (SQL Server) in which our record will be inserted.
2. Create a store procedure to insert data.
Front-end process (WebForm Process)
1. Add the connection string in the web config file.
2. Add an asp.net webform with C# language
3. Add some textbox (for Name, Phone No, EmailID, Password)according to your requirement and add a Registration button.
4. Now, come on the cs page (code-behind page) and write the logic and code to insert the record in a database.
Now, I am going to show you step by step image format tutorial to develop asp.net registration form. [Note: I am using Visual Studio 2015]
Step 1: Open Visual Studio and click on File--->New--> Website follow the below images.
Step 2: Now, Click on Template under it select C# and select Asp.net Empty Web Site then give website name and location and click on OK.
Step 3: Find the Solution Explorer and Right-click on Website and add webForm with a name Registration. See in below image.
Step 4: Add some TextBoxes and One Button to insert the record in the DataBase. And Design the webForm.
Registration.aspx code (Copy and paste it in your web form under <div> </div> section)
<table>
<tr>
<td>Name</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox></td>
<asp:RequiredFieldValidator ControlToValidate="txtname" Display="Dynamic" ErrorMessage="Enter Name" ForeColor="Red" ID="req1" runat="server" ValidationGroup="Save"></asp:RequiredFieldValidator>
</tr>
<tr>
<td>Email</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
<asp:RequiredFieldValidator ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Enter Email" ForeColor="Red" ID="RequiredFieldValidator1" runat="server" ValidationGroup="Save"></asp:RequiredFieldValidator>
</tr>
<tr>
<td>Address</td>
<td>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox></td>
<asp:RequiredFieldValidator ControlToValidate="txtAddress" Display="Dynamic" ErrorMessage="Enter Address" ForeColor="Red" ID="RequiredFieldValidator2" runat="server" ValidationGroup="Save"></asp:RequiredFieldValidator>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox></td>
<asp:RequiredFieldValidator ControlToValidate="txtPassword" Display="Dynamic" ErrorMessage="Password" ForeColor="Red" ID="RequiredFieldValidator3" runat="server" ValidationGroup="Save"></asp:RequiredFieldValidator>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Register" ValidationGroup="Save" />
</td>
</tr>
</table>
Step 5: Add connection in WebConfig under <configuration> tag
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<connectionStrings>
<add name="MyCon" connectionString="initial catalog=Test; integrated security=true; data source=." />
</connectionStrings>
Step 6: Create Table and procedure in MS SQL server
crate database Test
use Test
create table user_Registration
(
UID int identity(1,1),
UName varchar(50),
UEmail varchar(50),
UAddress varchar(50),
UPassword varchar(50)
)
create proc sp_Insert
@Name varchar(50),
@Email varchar(50),
@Address varchar(50),
@Password varchar(50)
as
begin
insert into user_Registration (UName,UEmail,UAddress,UPassword) values(@Name,@Email,@Address,@Password)
end
Step: 7
.Cs page
Write code on Button button_Onclick event
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class Registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("sp_Insert", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
Response.Write("<script> alert('Registered Sucessfully'); </script>");
}
}
}
Also Read:
Bind Country State City DropDown Using SQL Server
Bind Country State City DropDown WithOut Using SQL Server
Finally, Record is inserted by the asp.net registration. If you get any problems. Please feel free to comment below.
create proc sp_Insert
ReplyDelete@Name varchar(50),
@Email varchar(50),
@Address varchar(50),
@Password varchar(50)
how and where i create this
Create it in the database
Deletein database
ReplyDeleteCan you please remove error from program which I provide you..I am in very bad situation.. please help me 🙏🙏😭😭😭😭
ReplyDeleteyes please tell, I will help you on anydesk
DeleteCan you please remove the error from code which I provide you.. please please please please help me I am in very bad situation 😭😭🙏🙏🙏
ReplyDeleteyou can mail me your source on [email protected]
Deleteprotected void btnSave_Click(object sender, EventArgs e)
ReplyDelete{
SqlCommand cmd = new SqlCommand("sp_Insert", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", txtname.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
getting error saying no context defined
Check your database connection string...
DeletePost a Comment