Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebApplication1.Admin.Login" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="margin: 200px;">
    
        <table align ="center" class="style1" style="border :1px ridge #999999; width: 450px;">
        
        <tr>
         <td align="center" colspan="2">
         <asp:Label ID="Label1" runat="server" Text="Shopping Adminpanel" ForeColor="Blue" 
                 style="font-family: Aharoni"></asp:Label>
                 <hr />
        </td>
        </tr>
        <tr>
        <td align="center" style="width: 50%;">
        LoginID :
        </td>
        <td style="width: 50%;">
        <asp:TextBox ID="txtLoginId" runat="server"></asp:TextBox>
        </td>
        </tr>
        <tr>
        <td align ="center"style="width: 50%;">
        Password :
        </td>
        <td style="width: 50%;">
        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        </td>
        </tr>
        <tr>
        <td align ="center"style="width: 50%;"> 
         
        </td>
        <td style="width: 50%;">
        <asp:Button ID="btnLogin" runat="server" Text="Login" onclick="btnLogin_Click" ></asp:Button>
        </td>
        </tr>

        <tr>
        <td align="center" colspan="2"> 
        <hr />
        <asp:Label ID="lblAlert" runat="server" ForeColor="Red" 
                style="font-family: Aharoni" ></asp:Label>
        </td>
        </tr>
        </table>
    
    </div>
    </form>
</body>
</html>


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
namespace WebApplication1.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtLoginId.Focus();
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string LoginID = WebConfigurationManager.AppSettings["AdminLoginId"];
            string Password = WebConfigurationManager.AppSettings["AdminPassword"];

            if (txtLoginId.Text == LoginID && txtPassword.Text == Password)
            {
                Session["shopping"] = "shopping";
                Response.Redirect("~/Admin/AddNewProducts.aspx");
            }
            else
            {
                lblAlert.Text = "Incorrect Login/Password";
            }
        }
    }
}
Posted
Updated 19-Mar-17 21:01pm
v2
Comments
Karthik_Mahalingam 20-Mar-17 3:16am    
Storing userid and password in config file ?? why??
Member 13059491 20-Mar-17 3:23am    
because it's Admin Login Panel
Karthik_Mahalingam 20-Mar-17 6:49am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Member 13059491 20-Mar-17 3:24am    
<appsettings>
<add key="AdminLoginId" value="admin"/>
<add key="AdminPassword" value="123"/>
Karthik_Mahalingam 20-Mar-17 6:52am    
are you getting the value in LoginID and Password

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900