Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevon K. Hayes 255 posts 281 karma points
    Jun 28, 2010 @ 22:50
    Kevon K. Hayes
    0

    Dynamically Changing CSS in Umbraco

    I'm using a Macro to change the stylesheet in umbraco.  Using Firebug the CSS is getting changed in the head tag, however the UI isn't changing as it does w/test pages.

    public string _browserVer = "";
    public string _CSSFile = "";

    protected void Page_Init(object sender, EventArgs e)
     {            
                HtmlLink css = new HtmlLink();
                _browserVer = Request.UserAgent.ToString();

                if (_browserVer.Contains("MSIE 7.0"))
                {
                    _CSSFile = "css/MainIE7.css";
                }
                css.Href = _CSSFile;

                css.Attributes["rel"] = "stylesheet";

                css.Attributes["type"] = "text/css";

                css.Attributes["media"] = "all";

                Page.Header.Controls.Add(css);
    }

    Is there preferred way to do this or is this the recommended way to do this?

  • Jeff Grine 149 posts 189 karma points
    Jun 28, 2010 @ 23:18
    Jeff Grine
    0

    Not sure about the preferred method, but could the problem be that you're missing the leading slash on the Href?

  • Kevon K. Hayes 255 posts 281 karma points
    Jun 28, 2010 @ 23:57
    Kevon K. Hayes
    0

    I tried both ways actually, because I found out the hard way that Umbraco adds "masterpages/" to your css path if you don't preceed your href w/ a "/".

     

  • Kevon K. Hayes 255 posts 281 karma points
    Jun 30, 2010 @ 23:44
    Kevon K. Hayes
    0

    Believe it or not I solved this issue by putting CSS styles in the main .css file for the site.  I believe it was a relative/absolute path issue.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies