We help IT Professionals succeed at work.

AS.NET 2.0 detect browser screen size

Judgester asked
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)?

Watch Question

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

Senior Web Developer
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.
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.


Explore More ContentExplore courses, solutions, and other research materials related to this topic.