-2

I keep getting the error

The name '****' does not exist in the current context

when trying to start the application. No idea why. No spelling error, I've checked it over and over and I'm not sure if I've missed something out? The error occurs for TxtUsername, TxtPassword and LblMessage Code:

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 MusicShop.Admin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            string Username = WebConfigurationManager.AppSettings["AdminLoginID"];
            string Password = WebConfigurationManager.AppSettings["AdminPassword"];

            if (TxtUsername.Text == Username && TxtPassword.Text == Password)
            {
                Session["MusicShopAdmin"] = "MusicShopAdmin";
                Response.Redirect("#/Admin/AddNewSong.aspx");
            }
            else
            {
                LblMessage.Text = "Wrong Username or Password";
            }
        }
    }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Have you tried debugging? On which line did the error occur? It has to be some unrecognized variable – jmc Jul 02 '15 at 12:32
  • Where have you defined `TxtPassword`, `TxtUsername` and `LblMessage`? – Matias Cicero Jul 02 '15 at 12:34
  • 1
    That means the page doesn't have controls defined with those IDs, or that the page or its designer is in a different namespace. Try understanding the error and searching for solutions. You also may not want to roll your own authentication. – CodeCaster Jul 02 '15 at 12:34
  • 3
    Show your aspx page. Might be you haven't defined runat="server" – Litisqe Kumar Jul 02 '15 at 12:35
  • http://stackoverflow.com/questions/20043531/txtusername-and-txtpassword-controls-does-not-exist-in-the-current-context-e – Tim Schmelter Jul 02 '15 at 12:37

1 Answers1

0

Thanks for the help, I did look into it and it was a fault of my own, I had originally named the Web form LoginAdmin, then renamed it to Login, so to my own surprise I had just deleted it and made a new web form and copy & pasted the code and it worked...

Thanks for all the suggestions though, I'll keep them in mind in the future!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129