Get browser window size from C# codebehind

Discussion in 'ASP .Net' started by Just D., Mar 30, 2005.

  1. Just D.

    Just D. Guest

    How can we get the browser window size from C# codebehind? What's the
    easiest way to do that?

    Just D.
    Just D., Mar 30, 2005
    #1
    1. Advertising

  2. Just D.

    darrel Guest

    > How can we get the browser window size from C# codebehind? What's the
    > easiest way to do that?


    You'd have to grab the information client side with javascript and send it
    back to the server on postback.

    -Darrel
    darrel, Mar 30, 2005
    #2
    1. Advertising

  3. Just D.

    Just D. Guest

    HI Darrel,

    I will try to explain. The significant headache is to create a universal
    interface fitting any screen size. If the user resizes the browser it's a
    good idea to adopt the interface to its needs. I'm trying to replace some of
    the rulers made by JPG/GIF images by something more flexible like panels, or
    simply drawing on the form, it's possible but I need to know the real size
    of current frame where I'm drawing on. That's why this question appeared.
    From one size I could use something standard like fill the frame, etc. but
    if I need to modify the color using the position of the line it's harder, I
    need to know the line length to draw it correctly.

    If anybody can propose anything more efficient it would be nice, but I'm
    currently seeing only this solution.

    If I could get the browser window/frame size while the user resizes it, then
    it would solve these problems because it's possible to recreate the
    graphics, it's fast.

    Another one method is - to use JAVA scripts to draw on the remote side
    directly without any post backs. More efficient way, but is it really easier
    for programming?

    Just D.

    "darrel" <> wrote in message
    news:O%...
    >> How can we get the browser window size from C# codebehind? What's the
    >> easiest way to do that?

    >
    > You'd have to grab the information client side with javascript and send it
    > back to the server on postback.
    >
    > -Darrel
    >
    >
    Just D., Mar 30, 2005
    #3
  4. Just D.

    darrel Guest

    > I will try to explain. The significant headache is to create a universal
    > interface fitting any screen size. If the user resizes the browser it's a
    > good idea to adopt the interface to its needs. I'm trying to replace some

    of
    > the rulers made by JPG/GIF images by something more flexible like panels,

    or
    > simply drawing on the form, it's possible but I need to know the real size
    > of current frame where I'm drawing on. That's why this question appeared.
    > From one size I could use something standard like fill the frame, etc. but
    > if I need to modify the color using the position of the line it's harder,

    I
    > need to know the line length to draw it correctly.


    Consider using CSS for this. You can do what you are talking about, but it's
    typically much easier to just use CSS.

    For instance, if you have a rule, you can just assign a border to a div set
    to 100% width, and it will resize as needed.

    Redrawing the interface on postback based on viewport size is certainly
    doable, but not really sure if it's worth the effort.

    -Darrel
    darrel, Mar 30, 2005
    #4
  5. I don't think you can even get the browser size beyond using the client side
    function getBoundingClientRect(), but I haven't had any luck really
    determining the size of the browser. There is also a screen.width,
    screen.height property that will return the screen resolution the browser is
    on.

    If you do find a way, you will need to send this information back to the
    server, so you can do something with it. Plus, what will stop your user
    from resizing their browser window?

    HTH,

    bill


    "Just D." <> wrote in message
    news:0jE2e.2522$k57.1466@fed1read07...
    > How can we get the browser window size from C# codebehind? What's the
    > easiest way to do that?
    >
    > Just D.
    >
    >
    William F. Robertson, Jr., Mar 31, 2005
    #5
  6. Just D.

    Just D. Guest

    Thanks, William,

    I found a better way - all controls are using %% instead of pixels and it
    works just great and on the client side. Yes, it brings some disadvantages
    during development, but it price is good - the convenient resizable
    interface.

    Just D.


    >I don't think you can even get the browser size beyond using the client
    >side
    > function getBoundingClientRect(), but I haven't had any luck really
    > determining the size of the browser. There is also a screen.width,
    > screen.height property that will return the screen resolution the browser
    > is
    > on.
    >
    > If you do find a way, you will need to send this information back to the
    > server, so you can do something with it. Plus, what will stop your user
    > from resizing their browser window?
    Just D., Mar 31, 2005
    #6
    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. RJN
    Replies:
    1
    Views:
    8,731
    Patrik Löwendahl [C# MVP]
    Oct 10, 2004
  2. Andreas Klemt
    Replies:
    6
    Views:
    11,001
    Peter Theill
    Nov 28, 2004
  3. UJ
    Replies:
    2
    Views:
    7,491
    John Timney \(ASP.NET MVP\)
    Jun 27, 2005
  4. =?Utf-8?B?KioqKiBLaXRlT3JlZ29uICoqKio=?=

    get browser window size in code behind

    =?Utf-8?B?KioqKiBLaXRlT3JlZ29uICoqKio=?=, Jan 19, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    1,763
    Bharathi Kumar
    Jan 19, 2007
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,534
    Michael Jung
    May 25, 2008
Loading...

Share This Page