Happy New Year 2014

POLL OF THE DAY
How do you back up your personal data?






Want to create a new poll now?
(Login Required)

How do you back up your personal data?

OptionsVotes% 
USB thumb drive 0 0.00
External hard drive 3 100.00
Optical disc 0 0.00
Memory card 0 0.00
Online backup service 0 0.00
Multiple methods 0 0.00
Network-attached storage device 0 0.00

Total Responses: 3

Not scientifically valid. Results are updated every 15 minutes.

 

Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver

Author: Renuka Email: ********
Last Updated: 10/26/2012 10:25:49 PM Views:
67498
Level: Beginner Downloads: 1212
   

Introduction

This article explains about creating a simple registration or signup and login or sign in form using asp.net, c#.net and sqlserver.

Registration formLogin form

Follow the steps as described below to create the registration form and login form as shown above.

Creating Database:

  1. Create a databse in sqlserver with name 'TestDB'
  2. Next create a table with fields as shown in picture.
Registration form table

Creating Registration or signup form:

  1. Now create a new website using visual studio 2008 0r 2010.
  2. Design the registraion form and login form as shown in above pictures. In these two forms, validation controls are used to validate the fields as per requirement. To know about validation controls in asp.net read the following article.
  3. Add connection string property in web.config file as shown below.
    <configuration>
      <connectionStrings>
        <add name="CM_Connection" connectionString="data source=localhost;Initial Catalog=TestDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.web>
    Note:In this web.config file, the connection string name is 'CM_Connection'. You can change data source to your local server name (here it is localhost).
  4. Next in the 'CreateUser' button click event write the following code.
    if (Page.IsValid)
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CM_Connection"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand();
                    Guid guid;
                    guid = Guid.NewGuid();
                    string sql = "INSERT INTO TestDB_RegisterUser (registeruser_id,registeruser_username,registeruser_email,registeruser_password";
                    sql += " ,registeruser_createdon,registeruser_modifiedon,registeruser_rowstate)";
                    sql += "VALUES (@ID,@Username,@Email,@Password,@Createdon,@Modifiedon,@Rowstate)";
                    cmd.Parameters.AddWithValue("@ID", guid);
                    cmd.Parameters.AddWithValue("@Username", UserName.Text.Trim());               
                    cmd.Parameters.AddWithValue("@Email", Email.Text.Trim());
                    cmd.Parameters.AddWithValue("@Password", Password.Text);
                    cmd.Parameters.AddWithValue("@Createdon", DateTime.Now);
                    cmd.Parameters.AddWithValue("@Modifiedon", DateTime.Now);
                    cmd.Parameters.AddWithValue("@Rowstate", 1);                
                    cmd.Connection = con;
                    cmd.CommandText = sql;
                    con.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                        ErrorMessage.Text = "Registered successfully.";                    
                    }
                    catch(Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
    Note: You can check the validity of a Page by checking the Page.IsValid property. For this property to return true, all validation server controls in the current validation group must validate successfully. You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick event handler for an ASP.NET server control that initiates form processing. In simple words the Page.IsValid property tells you whether the validation succeeded or not.

In the above method after Page.IsValid, insert the record into database as shown. This finishes the registration form.

Creating Signin or Login form: In the 'Log In' button click event write the code as shown below.

 stringemail = UserName.Text.Trim();
string pwd = Password.Text;
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CM_Connection"].ConnectionString))
{
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = con;
    // cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "SELECT registeruser_id,registeruser_username, registeruser_email,registeruser_password FROM TestDB_RegisterUser where registeruser_email='" + email + "' and registeruser_password='" + pwd + "' and registeruser_rowstate<3 ";
    con.Open();
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
    da.Fill(dt);

    if (dt.Rows.Count > 0)
    {
        Session.Add("UserID", dt.Rows[0][0].ToString());
        Session.Add("Username", dt.Rows[0][1].ToString());
        Session.Add("UserEmail", dt.Rows[0][2].ToString());
        Response.Redirect("~/Default.aspx", false);
    }
    else
    {
        FailureText.Text = "Invalid username or password";            
    }
}

The above method gets the record that matches with useremail and password. Otherwise the datatable will be empty which is used to show 'Invalid username or password' to the user.

Thus you can create a registration form and log in form using asp.net

Comments/Suggestions are invited. Happy coding......!

Source Code can be download from here :
Comments
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Rggs dhhddhd
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
indrareddy
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nice
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nice code
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
thanks
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nice thats a osssam
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Web Development
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
vb.net all code need
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
we need coding for our project.our project paper is"attribute based access to scalable media in cloud assisted content sharing network" we proposed to speed up the decryption operation so plz help us.
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
great work!!!!!!!
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
LJLKMLKM;LE;T;
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
you have mentioned the link with login page and logout page then where is the logout coding
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
please help me
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
i am learner about asp.net please help to download code
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
learn
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
dfar
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
I AM NEW TO THIS TECHNOLOGY
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
bgfbf
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
need some help
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Great. in finally and after registration just add con.Close()
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
ert
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
http://codemyne.net/articles/asp/CaptchaImage.axd?guid=983abe64-dbd0-43e1-be8a-d0f36251b977
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
need to download
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
good
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
I want to download source code asp.net with sql sever by using C#
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
dfjkfjkds
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
gud 1... post was an asset...
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
getting login error i.e invalid username and password
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
hi
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
its too good..it helps me to make a registeration form and solve my id genrate problem
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Thankz a lot...nice and simple to understand
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nothing
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
dowamload
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nice
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
thanks to this site,those thing helps the user to know about the .net clealy.
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
ryty
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
plz give me a how to create a login in mvc 4 help of sql server 2008
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
how to create login form
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
how to create login form
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Have you tried adding a password protected folder to this and does it work? It doesn't work for me. Thanks
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
hello
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
nice
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
you have dose most languages to teaching
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
hiiiiiiiiii
rep:Creating a Simple Registration or Signup and Login or Signin Form using Asp.Net, C#.Net and Sqlserver
Help me
Post your comments:

Name :    
Email :      
Subject :  
Message :    
Type the word :    
 
 
 


Contact us

You might also like this!