The name 'controlname' does not exist in t

2019-01-01 05:41发布

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.

17条回答
谁念西风独自凉
2楼-- · 2019-01-01 06:28

this error often occurs when you miss runat="server" .

查看更多
流年柔荑漫光年
3楼-- · 2019-01-01 06:28

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.

查看更多
栀子花@的思念
4楼-- · 2019-01-01 06:29

exclude any other pages that reference the same code-behind file, for example an older page that you copied and pasted.

查看更多
余生无你
5楼-- · 2019-01-01 06:31

I had the same issue, my problem was not having space between two attributes"

AutoGenerateColumns="False"DataKeyNames="ProductID"

instead of

AutoGenerateColumns="False" DataKeyNames="ProductID"
查看更多
时光乱了年华
6楼-- · 2019-01-01 06:31

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.

查看更多
登录 后发表回答