I have this code snippet
<li class='<asp:Literal ID="litTest1" runat="server" />'>stuff</li>
On my computer, if I try to build the app in my VS2010, it gives the “does not exist in the current context” error and doesn’t register the control in Designer.cs file.
When I remove it from single quotes and just place it somewhere in the code, it works perfectly. Also, if I manually code these controls in the designer.cs, it compiles and works just fine.
The weirdest thing is that the code compliles just fine on another computer even if it’s inside the single quotes.
Could it be a matter of some VS2010 update that I haven’t installed?
It’s not a VS2010 issue..it’s a syntax issue
When you do this:
Your output will be a list item with no css class:
You can’t access litTest from the codebehind..it won’t recognize the control in that syntax.
What you can do instead is leave the literal on the page:
Then add the html on the backend: