How to call css file dynamically based on browser type

We know that all our browsers will be behaves differently, so handling these browsers are bit difficult . Here we have one option we can call different css file based on the browser type. Now let us see How to call css file dynamically based on browser type?

if(Request.Browser.Browser == "IE")
{
HtmlLink css = new HtmlLink();
css.Href = ResolveClientUrl("~/style/StyleSheet.css");
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}


if(Request.Browser.Browser == "CHROME")
{
HtmlLink css = new HtmlLink();
css.Href = ResolveClientUrl("~/style/StyleSheet2.css");
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}



Happy coding :).

Leave a Reply

Your email address will not be published. Required fields are marked *