Last post May 25, 2010 11:09 AM by coalvilledave
Dec 30, 2007 03:17 AM|jbrozek|LINK
Hope I'm asking this in the correct place, here we go. I've got a solution (ASP.NET Web Project) in VS.NET 2008 that looks like this (only showing important parts)
The site.master has a link to the ie.css style sheet. Everything looks fine in the browser when I run it. But 2008 is giving me "The class or CssClass value is not defined" warnings on classes used in the html of the Header.ascx file. I've seen mention of
this issue with some of the Beta 2008's but I'm not running a beta. Anybody have a solution? I should be able to shape projects this way I would think. Thanks for any help.
Dec 30, 2007 03:37 AM|noahb|LINK
I've had this problem in 2005 -- it's a pain. Can you tell me how you're defining where ie.css is placed? If the site.master defines it as "style/ie.css" then it's possible the Header.ascx also looks there, but this relative path becoms "/ctrl/style/ie.css"
and VS complains. I don't really have a fix though, sorry, just if that's the problem then there might be ways to address is....
Dec 30, 2007 05:55 AM|Mikhail Arkhipov (MSFT)|LINK
ASCX is a user control which can be used in multiple pages. Each page technically can have separate style or theme applies. Thus, designer does not know which stylesheet to apply to the control until control is included in the page. Here is related thread:
Dec 30, 2007 09:54 PM|jbrozek|LINK
I understand, following that logic, why not give me options in VS to "don't validate user control CSS", does any body know if a setting like this exists?
Dec 31, 2007 01:16 AM|pbz|LINK
I second that...
Jan 24, 2008 05:23 PM|richardneverett|LINK
You can add stylesheet references to your user controls, which solves this problem and also means that they render correctly in the designer.
However, your rendered web page will then be littered throughout with stylesheet links (depending on how many you added to each user control, and how many usercontrols you have on your page) - which is far from ideal.
Feb 17, 2008 05:45 AM|alun65|LINK
If this bugs you, you can turn it off by checking this box (in Tools -> Options) : TextEditor->Validation
You may not want to do this, though… it could potentially save you time if you’re looking for a rendering bug.
Jul 21, 2008 11:31 PM|Hightechrider|LINK
Here's a trick to get rid of the annoying validation message ... add the CSS link in the ASCX but set it to runat="server" and set visible="false".
<link href="/css/main2.css" rel="stylesheet" type="text/css" runat="server" id="styleMain" visible="false" />
Aug 21, 2008 09:28 PM|nachsart|LINK
Hightechrider, Thanks for the tip ... it fixed things up nicely. [Yes]
Mar 24, 2009 09:23 PM|seed|LINK
What I don't get is that some of my classes show up and others do not? Why is visual studio so selective on what it displays? I have a masterpage with the css included there. On my usercontrol it's a guessing game as to what css classes will show up.
Mar 24, 2009 09:38 PM|Mikhail Arkhipov (MSFT)|LINK
In user control VS does not know which stylesheet to use. Same control can be included in two different pages with different sets of stylesheets.
Apr 02, 2009 09:28 PM|Vinny Davi|LINK
Remember, there are a lot of UI tools in Visual Studio at your disposal for building web forms / pages.
In addition to server controls and css, you also have skins and master pages. The original post was using a header.ascx file which I would imagine is being used in conjunction with the master page. The master page is
perfectly capable of housing the header info without the need of a specific server control.
Additionally, I ran into the same issue between the design view, the code view and then run time when trying to use a server control for a LoginView control I was trying to manipulate. I just couldn't seem to make all
of them jive even using all the suggestions , tricks and hacks above. Simply providing a skin for it , and not using a server control made everything work as expected in my situation.
What I'm finding is if you end up trying to implement a quick fix or a hack using Visual Studio (especially 2008) you may be fighting the technology and there may be an easier way. What I found over time is if you fight
technology, as that technology matures you may find yourself creating future bugs, as vendors such as Microsoft don't know about your hacks and tricks and can't possibly incorporate compatibility for them in future versions.
In summary, if you are spending too much time on something that should be relatively simple, take a step back and see if there's an easier way. :)
Apr 02, 2009 10:09 PM|Hightechrider|LINK
Refactoring away from a collection of self-contained controls into a single monolithic block of code is rarely a good idea from a maintainability and readability standpoint. Server controls and user controls both have their place.
Most user controls have a static set (usually one) of stylesheets that define their appearance. It's handy to be able to tell VS2008 that your user control uses a particular CSS file so you can code without warnings. It's also important for that CSS reference
not to find its way into your HTML output with every instance of the control on the page. Even if a user control can be displayed with a variety of CSS files (depending on which page it is on), you still need a way to edit it without warnings against at least
one of your CSS files. And you don't want to turn warnings off!
The solution I provided above handles all of these requirements.
CSS intellisense ASCX usercontrol
Apr 29, 2009 06:56 PM|SnakePliskn|LINK
Thank You HighTechRider! Keeps the userControl happy and doesn't send anything additional to the client. Allows me to keep the errors/warnings clear so I will me more likely to notice a real error. I like it [:D].
May 25, 2010 11:09 AM|coalvilledave|LINK
rather than HTML validation as a whole, which comes in useful sometimes. As far as I understand, standard html validation doesn't check for the existence of css class references anyway.