Detecting resolution of client browser

Discussion in 'ASP .Net' started by Grzegorz Klimsa, Jul 2, 2008.

  1. Hi !
    I have a problem wiht detecting resolution of client web browser
    I prepare several files of css style for different browsers and different
    resolutions,
    (such as : Style_1024x768.css ; Styleff_1024x768.css; Style_1280x1024.css ;
    Styleff_1280x1024.css )

    I want to set css style file depends on resolution browser

    I wrote this script to detect type of browsers, but i don't have any idea
    how to detect resolution ???

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    Inherits="_Default" %>
    <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 = "Style_1280x1024.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_10280x1024.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);
    }

    }

    Greetings
    Grzegorz
     
    Grzegorz Klimsa, Jul 2, 2008
    #1
    1. Advertising

  2. re:
    !> I want to set css style file depends on resolution browser

    There's many ways to do that.

    This Google search will help you find one you can use/adapt :
    http://www.google.com/search?hl=en&q=detect browser resolution

    re:
    !> if (type == "IE7")
    {
    !> myHtmlLink.Href = "Style_1280x1024.css";

    That someone uses IE7 doesn't mean that their
    screen resolution is necessarily set to 1280x1024.





    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espanol : http://asp.net.do/foros/
    ======================================
    "Grzegorz Klimsa" <> wrote in message news:...
    > Hi !
    > I have a problem wiht detecting resolution of client web browser
    > I prepare several files of css style for different browsers and different resolutions,
    > (such as : Style_1024x768.css ; Styleff_1024x768.css; Style_1280x1024.css ; Styleff_1280x1024.css )
    >
    > I want to set css style file depends on resolution browser
    >
    > I wrote this script to detect type of browsers, but i don't have any idea how to detect resolution ???
    >
    > <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    > <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 = "Style_1280x1024.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_10280x1024.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);
    > }
    >
    > }
    >
    > Greetings
    > Grzegorz
     
    Juan T. Llibre, Jul 3, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    1,009
    Andrew FPGA
    Sep 26, 2005
  2. Erik  Bethke
    Replies:
    0
    Views:
    655
    Erik Bethke
    Feb 21, 2005
  3. Erik  Bethke
    Replies:
    1
    Views:
    419
    Do Re Mi chel La Si Do
    Feb 21, 2005
  4. Bjorn Sagbakken

    Detecting screen resolution in server code?

    Bjorn Sagbakken, Dec 4, 2007, in forum: ASP .Net
    Replies:
    14
    Views:
    1,580
    Bjorn Sagbakken
    Dec 5, 2007
  5. Mortisus
    Replies:
    2
    Views:
    227
    Mortisus
    Mar 29, 2005
Loading...

Share This Page