Codebehind file doesn't recognize aspx-control

2019-09-08 19:12发布

问题:

I was given a webproject written with aspx/c#. When I loaded it into Visual Studio 2010, I got many error telling me that some controls in the code-behind files do not exist in the current context.

I checked for the common pitfalls, like wrong code-behind file name, missing runat-attribute, restart VS, reload project, yet nothing resolves the error.

What else can I do to check where the problem is?

回答1:

Try to change the code-behinde to CodeFile="where code locate", then it probably will work.



回答2:

inherit class for the markup file and code behind file should match ,and also make sure if these controls are not third party and may need referencing their dlls or something .If these controls are user controls(ascx) controls , make sure they are using the correct tagname in the register line at the top .



回答3:

Cudos to @03Usr the following link brought the answer:

ASP.NET controls cannot be referenced in code-behind in Visual Studio 2008

Deleting all designer files and converting the project als web application brought the designer files back, effectively making the controls referenceable again.



回答4:

This is a really annoying hack but if you delete the control from the aspx page and then save the page, then paste the control back onto the page and save again the code behind then seems to recognize the control. I keep running into this problem whenever I change an attribute like the ID.