create simple registration form in asp.net with database c#

In previous asp.net post we have learned how  to create dynamic login form in asp.net using database. Now, in this tutorials we will  learn how to create simple registration from in asp.net using database.

create simple registration form in asp.net with database
create simple registration form in asp.net with database

 Video tutorials for ASP.Net Registration Form


For create registration from first, create a table in sql server for registration. we have here created table “UserMst” in sql server for store the registration data.

The sql table “UserMst” like :

create simple registration form in asp.net with database
create simple registration form in asp.net with database

Open Visual Studio and create a new web site –>> Design asp.net web form for user registration.

The HTML Source code of registration form :

<table align="center" class="style1" style="border: thin solid #008080">
<tr>
<td colspan="3" 
style="border-bottom: thin solid #008080; font-weight: 700; text-align: center;">
User Registration Form</td>
</tr>
<tr>
<td class="style5">
&nbsp;</td>
<td class="style4">
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style6">
FirstName :
</td>
<td class="style4">
<asp:TextBox ID="txtfname" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
ControlToValidate="txtfname" ErrorMessage="!!" ForeColor="Red" 
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
LastName :
</td>
<td class="style4">
<asp:TextBox ID="txtlname" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
ControlToValidate="txtlname" ErrorMessage="!!" ForeColor="Red" 
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
City :
</td>
<td class="style4">
<asp:TextBox ID="txtcity" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
ControlToValidate="txtcity" ErrorMessage="!!" ForeColor="Red" 
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
Email :
</td>
<td class="style4">
<asp:TextBox ID="txtemail" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
ControlToValidate="txtemail" ErrorMessage="!!" ForeColor="Red" 
SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
ControlToValidate="txtemail" ErrorMessage="invalid email" ForeColor="Red" 
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style6">
Password&nbsp; :</td>
<td class="style4">
<asp:TextBox ID="txtpassword" runat="server" Width="120px" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
ControlToValidate="txtpassword" ErrorMessage="!!" ForeColor="Red" 
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
&nbsp;</td>
<td class="style4">
<asp:Button ID="btnregistration" runat="server" Text="Register" 
onclick="btnregistration_Click" />
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style5">
&nbsp;</td>
<td class="style2" colspan="2">
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
&nbsp;<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</td>
</tr>
</table>

The design of web form like :

create simple registration form in asp.net with database
create simple registration form in asp.net with database

Here, we use validation control for all textboxes in registration form. We use required field validator for all the textbox to check whether it is empty or not. and use Regular Expression Validation for check valid email textbox.

First add namespaces for sql connection.

using System.Data;
using System.Data.SqlClient;

The C# code for register button click :

 protected void btnregistration_Click(object sender, EventArgs e)
    {
        lblmsg.Text = "";
        SqlConnection SQLConn = new SqlConnection("Data Source=.\\SQLExpress; Initial Catalog=Blog; Integrated Security=True");        
        SqlDataAdapter SQLAdapter = new SqlDataAdapter("insert into UserMst values('" + txtfname.Text + "','" + txtlname.Text + "','"+txtcity.Text+"','"+txtemail.Text+"','"+txtpassword.Text+"')", SQLConn);
        DataTable DT = new DataTable();
        SQLAdapter.Fill(DT);


        SqlDataAdapter SQLAAdapter = new SqlDataAdapter("select * from UserMst", SQLConn);
        DataTable DTT = new DataTable();
        SQLAAdapter.Fill(DTT);

        GridView1.DataSource = DTT;
        GridView1.DataBind();

        lblmsg.Text = "Registration Done!!";
        txtfname.Text = "";
        txtlname.Text = "";
        txtemail.Text = "";
        txtcity.Text = "";
        txtfname.Focus();
    }

Download ASP.Net Registration Example Source Code

asp.net example

Leave a Reply

Your email address will not be published. Required fields are marked *