Detecting screen resolution in server code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bjorn Sagbakken

    Detecting screen resolution in server code?

    Can screen resolution be detected with server code (in Page_Load) ?

    I have tried this:
    public int Width =
    Convert.ToInt32 (System.Windows .Forms.Screen.P rimaryScreen.Wo rkingArea.Width );
    public int Height =
    Convert.ToInt32 (System.Windows .Forms.Screen.P rimaryScreen.Wo rkingArea.Heigh t);

    and sure enough, I get a couple of numbers; Width=1024 and Height=738 when
    running at 1024x768 - but I also get the same numbers when running at
    1280x1024 (?) - so I just don't know what I'm actually reading here.

    The idea is to rescale some controls to make the best out of the actual
    resolution, and if I could do this server side I would be happy. But if
    client script is the only way, well then that's the way.

    Anyone with an opinion on this?

    Bjorn


  • Eliyahu Goldin

    #2
    Re: Detecting screen resolution in server code?

    Do you mean the resolution on the client machine? You can get in on client
    side with javascript as window.screen.w idth and window.screen.h eight and
    pass these values to server side in hidden input controls.



    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    "Bjorn Sagbakken" <bjo-sag@online.nowr ote in message
    news:NO2dnXiUvr xHEMjaRVnzvQA@t elenor.com...
    Can screen resolution be detected with server code (in Page_Load) ?
    >
    I have tried this:
    public int Width =
    Convert.ToInt32 (System.Windows .Forms.Screen.P rimaryScreen.Wo rkingArea.Width );
    public int Height =
    Convert.ToInt32 (System.Windows .Forms.Screen.P rimaryScreen.Wo rkingArea.Heigh t);
    >
    and sure enough, I get a couple of numbers; Width=1024 and Height=738 when
    running at 1024x768 - but I also get the same numbers when running at
    1280x1024 (?) - so I just don't know what I'm actually reading here.
    >
    The idea is to rescale some controls to make the best out of the actual
    resolution, and if I could do this server side I would be happy. But if
    client script is the only way, well then that's the way.
    >
    Anyone with an opinion on this?
    >
    Bjorn
    >

    Comment

    • Bjorn Sagbakken

      #3
      Re: Detecting screen resolution in server code?

      "Nanda Lella[MSFT]" <NandaL@online. microsoft.comwr ote in message
      news:PE0A6%23pN IHA.4200@TK2MSF TNGHUB02.phx.gb l...
      Have you tried something like
      >
      int width = System.Windows. Forms.Screen.Pr imaryScreen.Bou nds.Width;
      int height = System.Windows. Forms.Screen.Pr imaryScreen.Bou nds.Height;
      Yes, now I have. I get the same result as before.
      But when I read the other answers, I realize this would only give me the
      resolution on the server, not on the client.
      So a client script is probably the neccessary approach anyway.

      Bjorn


      Comment

      • Mark Rae [MVP]

        #4
        Re: Detecting screen resolution in server code?

        "Bjorn Sagbakken" <bjo-sag@online.nowr ote in message
        news:MrWdncMs35 yYPMja4p2dnAA@t elenor.com...
        So a client script is probably the neccessary approach anyway.
        There is no other option...


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • Bjorn Sagbakken

          #5
          Re: Detecting screen resolution in server code?

          "Eliyahu Goldin" <REMOVEALLCAPIT ALSeEgGoldDinN@ mMvVpPsS.orgwro te in
          message news:ul3$TGqNIH A.5208@TK2MSFTN GP04.phx.gbl...
          Do you mean the resolution on the client machine? You can get in on client
          side with javascript as window.screen.w idth and window.screen.h eight and
          pass these values to server side in hidden input controls.
          Very good idea. Thanks a lot.

          Bjorn


          Comment

          • Bjorn Sagbakken

            #6
            Re: Detecting screen resolution in server code?

            "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
            news:uzQMlbqNIH A.5160@TK2MSFTN GP05.phx.gbl...
            "Bjorn Sagbakken" <bjo-sag@online.nowr ote in message
            news:MrWdncMs35 yYPMja4p2dnAA@t elenor.com...
            >
            >So a client script is probably the neccessary approach anyway.
            >
            There is no other option...
            Right. So now this works very well:
            Height=window.s creen.height
            I write the height/width into a hidden field. Upon the first UpdatePanel
            postback this value is stored in a session variable so I can re-use this on
            various actions. Great.

            Bjorn


            Comment

            • Bjorn Sagbakken

              #7
              Re: Detecting screen resolution in server code?


              "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
              news:uzQMlbqNIH A.5160@TK2MSFTN GP05.phx.gbl...
              "Bjorn Sagbakken" <bjo-sag@online.nowr ote in message
              news:MrWdncMs35 yYPMja4p2dnAA@t elenor.com...
              >
              >So a client script is probably the neccessary approach anyway.
              >
              There is no other option...
              Just one more issue:
              Ideally I want to dynamically detect the actual client browser size if this
              isn't in maximized mode.
              I tried "availHeigh t" instead of height, but the result is not quite clear
              (?)
              Any tip?

              Bjorn


              Comment

              • Larry Bud

                #8
                Re: Detecting screen resolution in server code?

                On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowr ote:
                "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote in messagenews:uzQ MlbqNIHA.5160@T K2MSFTNGP05.phx .gbl...
                >
                "Bjorn Sagbakken" <bjo-...@online.nowr ote in message
                news:MrWdncMs35 yYPMja4p2dnAA@t elenor.com...
                >
                So a client script is probably the neccessary approach anyway.
                >
                There is no other option...
                >
                Right. So now this works very well:
                Height=window.s creen.height
                I write the height/width into a hidden field. Upon the first UpdatePanel
                postback this value is stored in a session variable so I can re-use this on
                various actions. Great.
                You will also have to update the values when the user changes the
                browser size.

                Comment

                • Bjorn Sagbakken

                  #9
                  Re: Detecting screen resolution in server code?

                  "Larry Bud" <larrybud2002@y ahoo.comwrote in message
                  news:ab07f4d8-95a2-44eb-b927-b29ee795cc8f@e6 7g2000hsc.googl egroups.com...
                  On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowr ote:
                  >"Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote in
                  >messagenews:uz QMlbqNIHA.5160@ TK2MSFTNGP05.ph x.gbl...
                  >>
                  "Bjorn Sagbakken" <bjo-...@online.nowr ote in message
                  >news:MrWdncMs3 5yYPMja4p2dnAA@ telenor.com...
                  >>
                  >So a client script is probably the neccessary approach anyway.
                  >>
                  There is no other option...
                  >>
                  >Right. So now this works very well:
                  >Height=window. screen.height
                  >I write the height/width into a hidden field. Upon the first UpdatePanel
                  >postback this value is stored in a session variable so I can re-use this
                  >on
                  >various actions. Great.
                  >
                  You will also have to update the values when the user changes the
                  browser size.
                  I know. That will be the next task.

                  Bjorn


                  Comment

                  Working...