473,657 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Dec 4 '07 #1
8 5349
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]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Bjorn Sagbakken" <bj*****@online .nowrote in message
news:NO******** *************@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

Dec 4 '07 #2
"Nanda Lella[MSFT]" <Na****@online. microsoft.comwr ote in message
news:PE******** ********@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
Dec 4 '07 #3
"Bjorn Sagbakken" <bj*****@online .nowrote in message
news:Mr******** *************@t elenor.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.orgwro te in
message news:ul******** ******@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
Dec 4 '07 #5
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:uz******** ******@TK2MSFTN GP05.phx.gbl...
"Bjorn Sagbakken" <bj*****@online .nowrote in message
news:Mr******** *************@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
Dec 4 '07 #6

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:uz******** ******@TK2MSFTN GP05.phx.gbl...
"Bjorn Sagbakken" <bj*****@online .nowrote in message
news:Mr******** *************@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
Dec 4 '07 #7
On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowr ote:
"Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote in messagenews:uz* *************@T K2MSFTNGP05.phx .gbl...
"Bjorn Sagbakken" <bjo-...@online.nowr ote in message
news:Mr******** *************@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.

Dec 5 '07 #8
"Larry Bud" <la**********@y ahoo.comwrote in message
news:ab******** *************** ***********@e67 g2000hsc.google groups.com...
On Dec 4, 2:43 pm, "Bjorn Sagbakken" <bjo-...@online.nowr ote:
>"Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote in
messagenews:uz **************@ TK2MSFTNGP05.ph x.gbl...
"Bjorn Sagbakken" <bjo-...@online.nowr ote 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
8587
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
2731
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 desktop resolution. I have tried trapping the following events: 1) SDL_ACTIVEEVENT 2) SDL_VIDEOEXPOSE
1
2857
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 desktop resolution. I have tried trapping the following events: 1) SDL_ACTIVEEVENT 2) SDL_VIDEOEXPOSE 3) SDL_VIDEORESIZE
5
4403
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: I would like to detect, get values for, the screen resolution in px but in a code behind. Is this possible? There is a System.Windows.Forms.Screen class for the Windows client side, why are there none for browser/ASP.NET client?
3
5645
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 Framework. And I see others doing the same mis-posting to dotnet.general which appears to be gearded more towards windows applications. What are General and Framework for options under .NET Development! After exhausting my search on the MS...
18
11641
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
4149
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
4146
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 ; Styleff_1024x768.css; Style_1280x1024.css ; Styleff_1280x1024.css ) I want to set css style file depends on resolution browser I wrote this script to detect type of browsers, but i don't have any idea
3
2156
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 is set to. I'd also like to know what windows has detected as the default screen res. I'd also like to find out information about what monitor is hooked up to the computer. I realize this isn't always right but I'd like to know what windows is...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.