---
title: "Login Control in ASP.Net"  
description: "There are many times comes when a web application having a login page to authenticate user. User can create own login control but visual studio also e"  
author: "Anonymous User"  
published: 2011-08-28  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/627/login-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 3 minutes  

---

# Login Control in ASP.Net

There are many times comes when a web application having a login page to authenticate user. User can create own login control but visual studio also enables this option to create login control for saving time. There we have used built-in feature in visual studio to create login page with help of by using default login control.\

##### Let’s see the brief demonstration of using default login control.

Step 1: first open visual studio and select new project from file menu and then click on website.

Step 2: After successful creating new project then click on toolbox from left pane, drag login control from left pane and drop it on your web page.

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/55ea6ec6-e77f-4be5-8c16-fc3d73ce0d5d.png)

Step 3: after dropping it on your web page it will appear as follows

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/9bf21412-29da-4fef-b0bd-6d9382dbcfb3.png)

Step 4: If you want to change formatting of login control then click login task button and select Auto Formatting

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/f3e22c8a-aa71-402e-bea9-46d53492719a.png)

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/4d29a092-07c8-4aa7-93fb-a6dfedab199a.png)

After selecting auto formatting option from login task then another formatting window appears where you have more choice to select login control formatting.

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/8101cff4-c60e-44d6-aebc-b6f78052355c.png)

After choosing the appropriate formatting then you can set properties of login control such as error messages, login control header text etc.

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/640b0f80-6ab9-4c00-a1ab-5f72cc771e40.png)

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/a07f4198-cabb-45f3-abfb-1a75210fbd00.png)

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/132f7e8f-dfba-4b06-afda-4a42d62ab6c6.png)

Now to validate user double click on login control and write the following code on Login1_Authenticate1 event

\

```
  /// <summary>     /// To check login user is authenticated or not      /// </summary>        private bool AuthenticateUser(stringusername,  stringpassword)    {         boolboolcheckReturn=false;         SqlConnection con= new SqlConnection(ConnectionString.ConnString());         SqlCommand cmd=new SqlCommand("select username from tbllogin where username ='"+username+"' and password ='"+password+"'", con);         //// use to explore Sqlcommand used text query         cmd.CommandType=System.Data.CommandType.Text;         /// connection open          con.Open();         /// ExecuteScalar() method reaturn object if there record found then return first row of first cell value          objectobj=cmd.ExecuteScalar();           /// check user is authenticate or not          if (obj!=null)         {             /// return true if user authenticate             return boolcheckReturn=true;         }         else         {             /// return false if user are not  authenticate             return boolcheckReturn=false;         }                }     /// <summary>     ///   authenticate event when click on login button       /// </summary>        protected void Login1_Authenticate1(objectsender,  AuthenticateEventArgse)    {         boolcheckAuthentication=false;         /// call AuthenticateUser method to validate user           checkAuthentication=AuthenticateUser(Login1.UserName, Login1.Password);         e.Authenticated=checkAuthentication;         if (checkAuthentication)         {             // successful login with full authentication              /// if user are authenticated then anoter home.aspx page are opened              Response.Redirect("home.aspx");         }           }
```

\

After run the program if you click on Log In button then following required field validator are displays.

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/f80dfe50-2d41-4cb2-bf21-71d2a434fa9f.png)

If you enter wrong Username or Password then following message are displays.

![Login Control in ASP.Net](https://www.mindstick.com/mindstickarticle/1bd75404-424e-4c84-ab55-28742117d6ad/images/91e27774-ffb6-4e03-b107-f7c5206e3965.png)

---

Original Source: https://www.mindstick.com/articles/627/login-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
