|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 "John Baima" <john@nospam.com> wrote in message This is a property of the browser which isn't passed to the server as part 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? 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...
Show quote
Hide quote
"Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote: Do you have any examples of this? I do mostly winform programming but>> 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... I would have thought that this would be something that lots of people would be interested in. -John John Baima 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/ ===================================================== Show quoteHide quote "John Baima" <john@nospam.com> wrote in message news:db10555jmuhbkghue4v3ei7v04tkpfig72@4ax.com... > "Mark Rae [MVP]" <mark@markNOSPAMrae.net> 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 "John Baima" <john@nospam.com> wrote in message Depends what you intend to do with the information, and whether you need to news:db10555jmuhbkghue4v3ei7v04tkpfig72@4ax.com... > Do you have any examples of this? know it client-side or server-side... Can you provide a bit more information about what you're trying to do...? "Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote: I need it server side. I have several text items in a database that I>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...? 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 "John Baima" <john@nospam.com> wrote in message Ignore that page completely. It is *seriously* out-of-date, e.g. <script 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. 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 But that's the way web browsers work! Users will be well used to this sort > 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. of behaviour... > So, I have to know how wide each of the elements are and how much screen Not possible server-side. The reason is that, unless you explicitly set the > I have to work with. 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...
Other interesting topics
xhtmlConformance mode="Strict"
Gridview binding twice Entity Framework - Reassigning child entity's parent Accessing GridViewRow.DataItem outside of GridView databinding events Need Sr DOT NET Developer | Seatle,Washington | 2+ years Space or comment between the lines can affect the program Dynamic generation of a table Deleting table row in table grid using ASP.NET MVC double click reaches to inline code CSS menu |
|||||||||||||||||||||||