Detecting browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grzegorz Klimsa

    Detecting browser

    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

  • Mark Rae [MVP]

    #2
    Re: Detecting browser

    "Grzegorz Klimsa" <grzegorzk19@wp .plwrote in message
    news:e30GHFHvIH A.3680@TK2MSFTN GP05.phx.gbl...
    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 ???
    HtmlLink objCSS = new HtmlLink();
    if (Request.Browse r.Type == "IE")
    {
    objCSS.Attribut es.Add("href", "IE.css");
    }
    else
    {
    objCSS.Attribut es.Add("href", "FF.css");
    }
    objCSS.Attribut es.Add("rel", "stylesheet ");
    objCSS.Attribut es.Add("type", "text/css");
    Header.Controls .Add(objCSS);


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Grzegorz Klimsa

      #3
      Re: Detecting browser

      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.mast er
      I copy & paste the same script to MasterPage.mast er 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(objec t sender, EventArgs e)
      {
      // Define an HtmlLink control.
      string type = Request.Browser .Type;
      HtmlLink myHtmlLink = new HtmlLink();


      if (type == "IE7")
      {
      myHtmlLink.Href = "Styl.css";
      myHtmlLink.Attr ibutes.Add("rel ", "stylesheet ");
      myHtmlLink.Attr ibutes.Add("typ e", "text/css");
      // Add the HtmlLink to the Head section of the page.
      Page.Header.Con trols.Add(myHtm lLink);
      }
      else
      {
      myHtmlLink.Href = "Styleff.cs s";
      myHtmlLink.Attr ibutes.Add("rel ", "stylesheet ");
      myHtmlLink.Attr ibutes.Add("typ e", "text/css");
      // Add the HtmlLink to the Head section of the page.
      Page.Header.Con trols.Add(myHtm lLink);
      }

      }
      </script>

      U¿ytkownik "Mark Rae [MVP]" <mark@markNOSPA Mrae.netnapisa³ w wiadomo¶ci
      news:e8zurPHvIH A.2188@TK2MSFTN GP04.phx.gbl...
      "Grzegorz Klimsa" <grzegorzk19@wp .plwrote in message
      news:e30GHFHvIH A.3680@TK2MSFTN GP05.phx.gbl...
      >
      >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.Browse r.Type),
      >but i have problem, how to load css file after execute
      >Request.Browse r.Type method in head section my ASP.NET page ???
      >
      HtmlLink objCSS = new HtmlLink();
      if (Request.Browse r.Type == "IE")
      {
      objCSS.Attribut es.Add("href", "IE.css");
      }
      else
      {
      objCSS.Attribut es.Add("href", "FF.css");
      }
      objCSS.Attribut es.Add("rel", "stylesheet ");
      objCSS.Attribut es.Add("type", "text/css");
      Header.Controls .Add(objCSS);
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Mark Rae [MVP]

        #4
        Re: Detecting browser

        "Grzegorz Klimsa" <grzegorzk19@wp .plwrote in message
        news:O4bfFMNvIH A.1328@TK2MSFTN GP03.phx.gbl...
        but in my solution I have another pages which use MasterPage.mast er
        I copy & paste the same script to MasterPage.mast er but CssStyle don't
        load.
        That's correct.
        What is the reason of this behaviour
        Content pages don't have headers...
        and how to reslove this problem ???
        Master.Header.C ontrols.Add(myH tmlLink);


        --
        Mark Rae
        ASP.NET MVP


        Comment

        Working...