Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Sat, 04 Jul 2009 17:43:53 -0500,    group: microsoft.public.dotnet.framework.aspnet        back       


Brwoser and screen width?   
I'd like to know how wide the browser window is at any given time as
well as the screen width with ASP.NET. Is there an easy way to do
that? Thanks.

-John
John Baima
date: Sat, 04 Jul 2009 17:43:53 -0500   author:   John Baima

Re: Brwoser and screen width?   
"John Baima"  wrote in message 
news:6nmv451h5kfu679d2qmelfhkig6q987vl2@4ax.com...

> I'd like to know how wide the browser window is at any given time as
> well as the screen width with ASP.NET. Is there an easy way to do
> that?

This is a property of the browser which isn't passed to the server as part 
of the request's server variables collection. This means that it's not 
available server-side directly.

However, you can retrieve this via client-side JavaScript. This is a bit of 
an inexact science, as different browsers use different properties for this 
information, e.g.

screen.width
screen.availWidth
window.innerWidth
document.documentElement.clientWidth
document.body.clientWidth

If you need these values server-side, your only option is to populate hidden 
fields with their values so that they can be inspected during postbacks...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
date: Sun, 5 Jul 2009 00:15:53 +0100   author:   Mark Rae [MVP]

Re: Browser and screen width?   
"Mark Rae [MVP]"  wrote:
>> I'd like to know how wide the browser window is at any given time as
>> well as the screen width with ASP.NET. Is there an easy way to do
>> that?
>
>This is a property of the browser which isn't passed to the server as part 
>of the request's server variables collection. This means that it's not 
>available server-side directly.
>
>However, you can retrieve this via client-side JavaScript. This is a bit of 
>an inexact science, as different browsers use different properties for this 
>information, e.g.
>
>screen.width
>screen.availWidth
>window.innerWidth
>document.documentElement.clientWidth
>document.body.clientWidth
>
>If you need these values server-side, your only option is to populate hidden 
>fields with their values so that they can be inspected during postbacks...

Do you have any examples of this? I do mostly winform programming but
I would have thought that this would be something that lots of people
would be interested in.

-John

John Baima
date: Sat, 04 Jul 2009 20:46:09 -0500   author:   John Baima

Re: Browser and screen width?   
re:
!> Do you have any examples of this?

http://www.google.com/search?hl=en&q=screen.width

re:
!> I would have thought that this would be something that lots of people would be interested in.

They are...




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
"John Baima"  wrote in message news:db10555jmuhbkghue4v3ei7v04tkpfig72@4ax.com...
> "Mark Rae [MVP]"  wrote:
>>> I'd like to know how wide the browser window is at any given time as
>>> well as the screen width with ASP.NET. Is there an easy way to do
>>> that?
>>
>>This is a property of the browser which isn't passed to the server as part
>>of the request's server variables collection. This means that it's not
>>available server-side directly.
>>
>>However, you can retrieve this via client-side JavaScript. This is a bit of
>>an inexact science, as different browsers use different properties for this
>>information, e.g.
>>
>>screen.width
>>screen.availWidth
>>window.innerWidth
>>document.documentElement.clientWidth
>>document.body.clientWidth
>>
>>If you need these values server-side, your only option is to populate hidden
>>fields with their values so that they can be inspected during postbacks...
>
> Do you have any examples of this? I do mostly winform programming but
> I would have thought that this would be something that lots of people
> would be interested in.
>
> -John
>
> John Baima
date: Sun, 5 Jul 2009 01:34:45 -0400   author:   Juan T. Llibre

Re: Browser and screen width?   
"John Baima"  wrote in message 
news:db10555jmuhbkghue4v3ei7v04tkpfig72@4ax.com...

> Do you have any examples of this?

Depends what you intend to do with the information, and whether you need to 
know it client-side or server-side...

Can you provide a bit more information about what you're trying to do...?


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
date: Sun, 5 Jul 2009 10:34:42 +0100   author:   Mark Rae [MVP]

Re: Browser and screen width?   
"Mark Rae [MVP]"  wrote:
>Depends what you intend to do with the information, and whether you need to 
>know it client-side or server-side...
>
>Can you provide a bit more information about what you're trying to do...?

I need it server side. I have several text items in a database that I
want to display and I want to get as many columns as possible in a
table, but I don't want the user to have to scroll right and left. So,
I have to know how wide each of the elements are and how much screen
I have to work with.

I did get the scheme of:

http://www.devcity.net/Articles/64/1/screenresolution.aspx

working and extended it to what I need. Now I just need to know the
width of text elements :-)

-John

John Baima
date: Sun, 05 Jul 2009 06:23:01 -0500   author:   John Baima

Re: Browser and screen width?   
"John Baima"  wrote in message 
news:7p2155175edhbjoq80uhdcral0snjp87q0@4ax.com...

> I did get the scheme of:
>
> http://www.devcity.net/Articles/64/1/screenresolution.aspx
>
> working and extended it to what I need.

Ignore that page completely. It is *seriously* out-of-date, e.g. <script 
language="javascript"> - the language tag of the <script /> element has been 
deprecated for nearly THIRTEEN years!!!

Did you read all of the comments at the bottom of the article? Specifically, 
what happens if the user changes their screen resolution?

Apart from that, obviously detecting the client machine's screen resolution 
(e.g. 1280*1024) does not tell you how the width of the client browser 
unless it is maximised - that's why you need to know the current width of 
the browser, not the width of the screen...


> I need it server side. I have several text items in a database that I
> want to display and I want to get as many columns as possible in a
> table, but I don't want the user to have to scroll right and left.

But that's the way web browsers work! Users will be well used to this sort 
of behaviour...


> So, I have to know how wide each of the elements are and how much screen
> I have to work with.

Not possible server-side. The reason is that, unless you explicitly set the 
width of DOM elements, the web browser will do this automatically as its 
parsing the HTML stream response being received from the webserver. And, by 
that time, it's too late for the server to do anything to the HTML stream...

Your best bet would be to set the widths of the controls explicitly and let 
the contents wrap...

I really do think you're making things unnecessarily difficult for 
yourself...


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
date: Sun, 5 Jul 2009 12:40:36 +0100   author:   Mark Rae [MVP]

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us