Detecting browser

  • Thread starter Thread starter Grzegorz Klimsa
  • Start date Start date
G

Grzegorz Klimsa

Hello

I have problem with ASP.NET in C# language.

I prepare two files of css style, one for ie ,second for firefox
I want to set css style file depends on browser type
I know how pull out info about sort of browser from browser (using
Request.Browser.Type),
but i have problem, how to load css file after execute Request.Browser.Type
method in head
section my ASP.NET page ???

Greetings
Grzegorz
 
I wrote smilar script, and put in to my default.aspx page and work correctly
:)
but in my solution i have another pages which use MasterPage.master
I copy & paste the same script to MasterPage.master but CssStyle don't load.

What is the reason of this behaviour and how to reslove this problem ???


<%@ Page Language="C#"%>
<script runat="server">

protected void Page_Init(object sender, EventArgs e)
{
// Define an HtmlLink control.
string type = Request.Browser.Type;
HtmlLink myHtmlLink = new HtmlLink();


if (type == "IE7")
{
myHtmlLink.Href = "Styl.css";
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");
// Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink);
}
else
{
myHtmlLink.Href = "Styleff.css";
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");
// Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink);
}

}
</script>
 
Back
Top