I have a web application that I'm working on (ASP.NET2.0 with C#, using VS2005). Everything was working fine, and all of a sudden I get the error:
Error 1 The name 'Label1' does not exist in the current context
and 43 others of the sort for each time that I used a control in my codebehind of the page.
This is only happening for 1 page. And it's as if the codebehind isn't recognizing the controls. Another interesting thing is that the intellisense isn't picking up any of the controls either..
I have tried to clean the solution file, delete the obj file, exclude the files from the project then re-add them, close VS and restart it, and even restart my computer, but none of these have worked.
this error often occurs when you miss
runat="server"
.In my case, when I created the web form, it was named as WebForm1.aspx and respective names (WebForm1). Letter, I renamed that to something else. I renamed manually at almost all the places, but one place in designer file was still showing it as 'WebForm1'.
I changed that too and got rid of this error.
exclude any other pages that reference the same code-behind file, for example an older page that you copied and pasted.
I had the same issue, my problem was not having space between two attributes"
instead of
I ran into this same issue. Apparently, you shouldn't call a class in the BLL the same name as one of the .aspx/.aspx.cs files. I thought they would not be in the same scope, etc. but it messed with Visual Studio's internal workings too much. I'm a bit surprised there isn't something to keep you from doing this if it is going to produce that type of error. Anyway, just delete the .aspx/.aspx.cs files and rebuild your project. Then bring them back in under another name. You can copy/paste your code into another editor if you don't want to retype it all back in.