I had to change some code that was created by another person in VS2008, I converted it to the VS2010 version and was working just fine until the moment I needed to change a master page file. The moment I opened it, it gave me a lot of “does not exist in the current context” errors from the code behind showing that the code behind file could not find some of the controls declared in the master page file.
So, the code that gets errors is like this:
<li class='<asp:Literal ID="litLIClass_Test1" runat="server"/>'>stuff</li>
As you can see, the <li> CSS class is being generated inside that ASP literal, but it seems that the ASP literal doesn’t get initialized.
However, it seemed to be working before, and I am trying to understand why it started giving me errors when I opened the page code for the first time in VS2010. Is there a particular setting that enables this kind of nesting? Could there be different settings in VS2008/2010?
In my experience, this is usually a Namespace not matching issue.
A few things to try:
web server is also turned off, Restart Visual Studio, Recompile (it
works sometimes in my experience). Make sure that the namespace in
your code behind file matches the namespace in your page (if it’s
WebForms). I assume this also includes the master page but I don’t
know, I do know that you can get this error when the ASPX and the
code behind namespaces are off.
cause of the error, especially when upgrading. Your code files
maybe identical but your web.config or what is referenced by default
might have changed.
code file, but I’ve never actually experienced that (nor do I do
that).
References:
(I had more reference links to post but I can’t because I don’t have the reputation yet). 😉