473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.Primar yScreen.WorkingArea.Width);
public int Height =
Convert.ToInt32(System.Windows.Forms.Screen.Primar yScreen.WorkingArea.Height);

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
Dec 4 '07 #1
8 5335
Do you mean the resolution on the client machine? You can get in on client
side with javascript as window.screen.width and window.screen.height and
pass these values to server side in hidden input controls.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:NO*********************@telenor.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.Primar yScreen.WorkingArea.Width);
public int Height =
Convert.ToInt32(System.Windows.Forms.Screen.Primar yScreen.WorkingArea.Height);

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

Dec 4 '07 #2
"Nanda Lella[MSFT]" <Na****@online.microsoft.comwrote in message
news:PE****************@TK2MSFTNGHUB02.phx.gbl...
Have you tried something like

int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.W idth;
int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.H eight;
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
Dec 4 '07 #3
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Mr*********************@telenor.com...
So a client script is probably the neccessary approach anyway.
There is no other option...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Dec 4 '07 #4
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:ul**************@TK2MSFTNGP04.phx.gbl...
Do you mean the resolution on the client machine? You can get in on client
side with javascript as window.screen.width and window.screen.height and
pass these values to server side in hidden input controls.
Very good idea. Thanks a lot.

Bjorn
Dec 4 '07 #5
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uz**************@TK2MSFTNGP05.phx.gbl...
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Mr*********************@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.

Bjorn
Dec 4 '07 #6

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uz**************@TK2MSFTNGP05.phx.gbl...
"Bjorn Sagbakken" <bj*****@online.nowrote in message
news:Mr*********************@telenor.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 "availHeight" instead of height, but the result is not quite clear
(?)
Any tip?

Bjorn
Dec 4 '07 #7
On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowrote:
"Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote in messagenews:uz**************@TK2MSFTNGP05.phx.gbl. ..
"Bjorn Sagbakken" <bjo-...@online.nowrote in message
news:Mr*********************@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.

Dec 5 '07 #8
"Larry Bud" <la**********@yahoo.comwrote in message
news:ab**********************************@e67g2000 hsc.googlegroups.com...
On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowrote:
>"Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote in
messagenews:uz**************@TK2MSFTNGP05.phx.gbl ...
"Bjorn Sagbakken" <bjo-...@online.nowrote in message
news:Mr*********************@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
Dec 5 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: dreamer | last post by:
I need to be able to detect different screen resolutions and then resize my applications forms, objects, fonts etc, to suit. Any ideas how to go about it? I use VB 5. Many thanks in advance.
0
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
1
by: Erik Bethke | last post by:
Hello All, I am trying to clean up some polish bugs with the Shanghai game I am working on and I am currently stuck on trying to get the right event for detecting when the user has changed the...
5
by: Chris | last post by:
After exhausting my search on the MS website, I can't find a straight answer. I fin dit hard to believe that MS left our something so useful in ASP.NET as screen resolution detection. Problem:...
3
by: Chris | last post by:
I think I placed this in the wrong news group so I'm moving it here. Suggestion to Microsoft make the categories more clear and make better sense. ASP.NET should be its own group, why bury under...
18
by: DavidS | last post by:
Have resW=screen.width; resH=screen.height in javascript. How can I read these values in ASP.NET source code - Page_Load function of code behind? Any suggestions?
35
by: Friendly_Lola | last post by:
What Screen Resolution do You use? 800 X 600 1024 X 768 1280 X 1024 Wow! 1600 X 1200 (i can't imagine this) I use 1024 X 768. For what resolution you optimize your web pages?
1
by: Grzegorz Klimsa | last post by:
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 ;...
3
by: Mufasa | last post by:
I have customers who install our product and then set the screen resolution to a crappy resolution so things don't display on the screen correctly. I'd like to know what the default monitor setting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.