Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Detecting screen resolution in server code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bjorn Sagbakken - 04 Dec 2007 17:26 GMT
Can screen resolution be detected with server code (in Page_Load) ?

I have tried this:
public int Width =
Convert.ToInt32(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width);
public int Height =
Convert.ToInt32(System.Windows.Forms.Screen.PrimaryScreen.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
Nanda Lella[MSFT] - 04 Dec 2007 18:01 GMT
Have you tried something like
 
int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

--------------------
>NNTP-Posting-Date: Tue, 04 Dec 2007 11:26:49 -0600
>From: "Bjorn Sagbakken" <bjo-sag@online.no>
[quoted text clipped - 11 lines]
>NNTP-Posting-Host: 84.202.85.158
>X-Trace:
sv3-Ji2rwuV7a67ups7LW5TgTZncplX98gcFY7uxwSCxqsZxDD4F212nilD+r3le+Hq/XjkfT+ZZ
xIVbmJ/!/4vLCgW8rON3o+7LgZgaWKh5DOEtuQ4cRwLQvt3aOPSqWv3SILfTjXbmIOVdAvwC0JRS
imztRLko
>X-Complaints-To: news-abuse@telenor.net
>X-DMCA-Complaints-To: news-abuse@telenor.net
>X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
>X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your
complaint properly
>X-Postfilter: 1.3.36
>Path:
TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTFEEDS02.phx.gbl!news-out.
cwix.com!newsfeed.cwix.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.icl.net!newsf
eed.fjserv.net!colt.net!feeder.news-service.com!xlned.com!feeder1.xlned.com!
amsnews11.chello.com!feeder1.cambrium.nl!feeder5.cambrium.nl!feed.tweaknews.
nl!63.218.45.11.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!216.196.
98.140.MISMATCH!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp
.dca.giganews.com!nntp.telenor.com!news.telenor.com.POSTED!not-for-mail
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:52379
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
[quoted text clipped - 18 lines]
>
>Bjorn

Signature

Thank You,
Nanda Lella,

This Posting is provided "AS IS" with no warranties, and confers no rights.

Juan T. Llibre - 04 Dec 2007 18:31 GMT
The problem, of course, is that using server code to determine screen resolution
will result in the *server* screen resolution being grabbed/returned.

I'd use Javascript to do that client-side.

<script language='javascript'>
function ClientScreenInfo()
{
 var = window.screen.width;
 var2 = window.screen.height;
}
</script>

...and store the values in hidden fields which you can manipulate in code.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> Have you tried something like
>
[quoted text clipped - 58 lines]
>>
>>Bjorn
Bjorn Sagbakken - 04 Dec 2007 18:48 GMT
> Have you tried something like
>
> int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
> int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.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
Mark Rae [MVP] - 04 Dec 2007 18:53 GMT
> So a client script is probably the neccessary approach anyway.

There is no other option...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Bjorn Sagbakken - 04 Dec 2007 19:43 GMT
>> 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
Larry Bud - 05 Dec 2007 21:05 GMT
> >> So a client script is probably the neccessary approach anyway.
>
[quoted text clipped - 5 lines]
> 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.
Bjorn Sagbakken - 05 Dec 2007 22:11 GMT
>> >> So a client script is probably the neccessary approach anyway.
>>
[quoted text clipped - 9 lines]
> You will also have to update the values when the user changes the
> browser size.

I know. That will be the next task.

Bjorn
Bjorn Sagbakken - 04 Dec 2007 20:05 GMT
>> 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
Mark Rae [MVP] - 04 Dec 2007 20:20 GMT
> Any tip?

http://books.google.com/books?id=dtqqcgFbKNsC&pg=PA570&lpg=PA570&dq=%22document+
body+parentnode+clientwidth%22&source=web&ots=Ogz3fC5SiR&sig=B48ZS5_QfLQC4oYFj14
MUqUtIU0


Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Bjorn Sagbakken - 04 Dec 2007 21:44 GMT
>> Any tip?
>
> http://books.google.com/books?id=dtqqcgFbKNsC&pg=PA570&lpg=PA570&dq=%22document+
body+parentnode+clientwidth%22&source=web&ots=Ogz3fC5SiR&sig=B48ZS5_QfLQC4oYFj14
MUqUtIU0

Thanks for a 1400 pages manual. I'm sure it't useful in many ways.
At a glance, I just didn't find anything regarding the current subject
hovewer....

Bjorn
Mark Rae [MVP] - 04 Dec 2007 22:42 GMT
>>> Any tip?
>>
[quoted text clipped - 3 lines]
> At a glance, I just didn't find anything regarding the current subject
> hovewer....

The link I gave you takes you straight to page 570, where you will find the
code that you require - did you read it...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Bjorn Sagbakken - 05 Dec 2007 17:38 GMT
>>>> Any tip?
>>>
[quoted text clipped - 6 lines]
> The link I gave you takes you straight to page 570, where you will find
> the code that you require - did you read it...?

I am sorry, Mark. I went straight to the top of the document to see what
kind of file this was, and started to browse the index. I just didn't
realize that you even had opened the book for me at the right page.

So it is hereby proven what they say: You can lead a horse to the water, but
you cannot make it drink.

(Thanks again)

Bjorn
Eliyahu Goldin - 04 Dec 2007 18:14 GMT
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.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> Can screen resolution be detected with server code (in Page_Load) ?
>
[quoted text clipped - 15 lines]
>
> Bjorn
Bjorn Sagbakken - 04 Dec 2007 19:01 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.