• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12061
  • Last Modified:

AS.NET 2.0 detect browser screen size

I am developing an ASP.NET web site that will be accessed by both computer and mobile devices. I would like to make sure the page content is set properly for the browsers screen size. This is of not an issue with computer based browsers but it is with mobile device browsers.

Is there a way to detect the browser window size?

I know I can detect the type and name of the browser so if the size is not detectable is there a list somewhere (webservice or static list)?

1 Solution
The only way I know to check screen resolution is using javascript.
<script language=javascript>
//Get screen resolution variables
var width=screen.width
var height=screen.height
window.open("frame.asp?Course=<%= strCourse %>&Width=" + width + "&Height=" + height,"_parent")

Open in new window

Sachintana DissanayakeSenior Web DeveloperCommented:
In ASP.NET you can check in the Browser object and get screen size (width and height) in pixels.

Another property that you can check is maximum size of the page that the browser can handle in bytes.
With the "Accepted Solution" I get 640 x 480 pixel resolution : Not True .
The problem may be that the solution offered by sachintana returns the screen resolution of the server not the client. This would work if the program was only running on the server but most times this is not the case. The javascript, although not asp.net, was the only way I could get the client screen resolution.
Ashish PatelCommented:
If you are planning to detect wide range of mobile phones than please use following free open source .net mobile api http://www.51degrees.mobi/Products/NETMobileAPI

It gives  detailed information of the device making the request and also has the facility to redirect user automatically to mobile landing page when request in coming from mobile device.

For e.g.
Hope this helps.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now