Create a Simple Login Form in ASP.NET using Visual Studio 2022

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="LoginFormASP.login" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <h1 align="center">Login Form</h1>

    <form id="form1" runat="server">

        <table align="center">

            <tr>

                <td>Username</td>

                <td>

                    <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td>Password</td>

                <td>

                    <asp:TextBox ID="txtPass" runat="server" TextMode="Password"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td></td>

                <td>

                    <asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click"/>

                </td>

            </tr>

        </table>

    </form>

</body>

</html>

ABOVE FILE IS login.aspx
















using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String username = txtUser.Text;
            String password = txtPass.Text;
            if (username == "admin" && password == "admin")
            {
                Response.Write("<script type='text/javascript'>alert('Login Successful')</script>");
            }
            else
            {
                Response.Write("<script type='text/javascript'>alert('Login Error')</script>");
            }
        }
    }
}
ABOVE FILE IS login.aspx.cs




Comments

Popular posts from this blog

Create a User Registration Form in ASP.NET using SQL Server, Visual Studio 2022 & Bootstrap

SqlCommand Class ADO.Net | ExecuteNonQuery | ExecuteReader | ExecuteScalar