0

I have several textboxes in my aspx file (not nested in any other controls), but when referenced in my C# file, I get the error that "The name 'controlname' does not exist in the current context." I have tried making a new project with the same code, converting to web application, and even deleting the designer.cs file just to convert to web app again out of frustration. The page was working fine until sometime yesterday, but seemingly arbitrarily stopped recognizing the ASP controls, as I didn't change anything other than adding a SQL read, which really shouldn't affect communication between the .aspx file and the .aspx.cs file. I really appreciate any advice or fixes, as I've lost a good few hours of work trying to figure out how to make these files talk to each other.

  • As posted above, I have both regenerated the designer.cs file several times and included runat="server" in all control tags. – user1488654 Jun 28 '12 at 13:45
  • Have you checked the `CodeBehind` and `Inherits` tags of your `<%@ Page .. %>` declaration in your .aspx file to ensure they match the file and class name of your .cs file? – Mike Guthrie Jun 28 '12 at 15:55

2 Answers2

0

It happens when your .ASPX.CS doesn't find the definition of the control, which is contained at the .DESIGNER file. Have you modified or removed these files? Could you post some of your code here?

And, a simple yet important advice: make sure to have the tag runat='server' in all of your controls.

Regards, Calil

Andre Calil
  • 7,652
  • 34
  • 41
0

Check that the properties of the .cs and .designer.cs files have their build actions set 'Compile'.

This can sometimes happen when the project file gets corrupted.

marvc1
  • 3,641
  • 3
  • 25
  • 34