Brwoser and screen width?

  • Thread starter Thread starter John Baima
  • Start date Start date
J

John Baima

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
 
Mark Rae said:
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
 
Mark Rae said:
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
 
Back
Top