Basic Login website without database connectivity

Basic Login website without database connectivity

Hello Friends, Today We will make a basic login website in which we will use two text boxes and three labels and a button.

Here is the design of the website. If you dont know how to create a website please follow our previous post “hello word asp .net website“.

basic login form in asp .net website
basic login form in asp .net website

The Design code is as :

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”default.aspx.cs” Inherits=”Admin_AdminLogin” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>Login</title>

</head>
<body “>
<form id=”form1″ runat=”server”>
<div>
<table cellpadding=”5px”>
<tr>
<td>
Username :
</td>
<td>
<asp:TextBox ID=”txtUserName” runat=”server” ></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<asp:TextBox ID=”txtPassword” TextMode=”Password” runat=”server” ></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td colspan=”2″ align=”center”>
<asp:Button ID=”btnLogin” runat=”server” Text=”Login”
onclick=”btnLogin_Click” />

</td>

</tr>

<tr>
<td colspan=”2″ align=”center”><asp:Label ID=”lblError” runat=”server” ForeColor=”Red”></asp:Label></td>
</tr>
</table>

</div>
</form>
</body>
</html>

Click on the button “Login” and write down the following code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_AdminLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnLogin_Click(object sender, EventArgs e)
{
string UserName = txtUserName.Text.ToString();
string Password = txtPassword.Text.ToString();

if (UserName==”login” && Password==”password”)
{
Response.Redirect(“home.aspx”);
}
else
{
lblError.Text = “Username and Password Are not Correct”;
}
}

}

website preview of login form in browser
website preview of login form in browser

As the code suggest, I had used username as “login” and “password” as password.

Use this to try to login the website. After clicking the login button you will see that there will be a new page name home.aspx which I created to show the use of response.redirect() function. This function is used to navigate to the given url(website address). The function response.redirect() uses a string as parameter and this can be absolute or reference url like here we have used a reference url.

To show error message we have used a label and we have assigned a text whenever a user used a wrong credentials. Please see the picture:

use of label control to show error message in asp .net
use of label control to show error message in asp .net

For password field textbox we use a property textmode=”password”  to hide the actual password characters.

We can also use placeholder property to set a watermark for text boxes like username and password.

To download complete project click here asp .net website login project without database connectivity

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

Leave a Reply

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

%d bloggers like this: