Do I need this bit of code in my App_Code/MenuAdapter.cs file?

Apr 27, 2010 at 8:38 AM

I'm using CSS Friendly Controls to stylize a navigation menu of mine. As of right now, that is all CSS Friendly Control Adapters is doing for me.

I have everything working great and displaying just how I want it. However, today I was checking to make sure the page conformed to W3C XHTML 1.0 Transitional standards and my page had a few errors.

First, "&" characters in the URL were not being properly written as "&." I was able to solve that easily by changing the following code in MenuAdapter.cs from:

string cssTag = "<link href=\"" + Page.ResolveUrl(filePath) + "\" type=\"text/css\" rel=\"stylesheet\" />";

To:

string cssTag = "<link href=\"" + Page.ResolveUrl(filePath).Replace("&", "&amp;") + "\" type=\"text/css\" rel=\"stylesheet\" />";

Problem solved... but I still didn't pass 1 part of validation. The CSS Friendly Controls are inserting <link> HTML elements into the body of my web page. Those need to be inserted into the head in order to pass validation.

1.) Can I somehow get those lines of code to be inserted into the <head> of my HTML, instead of the <body>?

2.) Do I even need those lines of code? I'm referring to this bit:

            // if filePath is not empty, embedded CSS exists -- register it
            if (!String.IsNullOrEmpty(filePath))
            {
                string cssTag = "<link href=\"" + Page.ResolveUrl(filePath).Replace("&", "&amp;") + "\" type=\"text/css\" rel=\"stylesheet\" />";
                if (!Page.ClientScript.IsClientScriptBlockRegistered(type, resource))
                    Page.ClientScript.RegisterClientScriptBlock(type, resource, cssTag, false);
            }

            // IEMenu6.css -- only add if it is embedded
            resource = "CSSFriendly.CSS.BrowserSpecific.IEMenu6.css";
            filePath = Page.ClientScript.GetWebResourceUrl(type, resource);

            // if filePath is not empty, embedded CSS exists -- register it
            if (!String.IsNullOrEmpty(filePath))
            {
                string cssTag = "<link href=\"" + Page.ResolveUrl(filePath).Replace("&", "&amp;") + "\" type=\"text/css\" rel=\"stylesheet\" />";
                if (!Page.ClientScript.IsClientScriptBlockRegistered(type, resource))
                    Page.ClientScript.RegisterClientScriptBlock(type, resource, cssTag, false);
            }

If I delete that code my page still displays fine in Firefox 3.x, and it now passes W3C validation (since those <link> tags aren't even being added to the page. But can this have any adverse effect? Will it cause display issues in certain browsers? I'm not sure what those WebResource.axd files even do anyways. If I try to view them in a browser I just get a 404 error.

So, can I get those <link> tags input into the <head> section of my HTML? And if not, do I even need the block of code posted above?