Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET c# get screen width in pixels

Tags:

c#

asp.net

I am trying to retrieve width of my browser in pixels but for some reason I am getting back 640, my resolution is at 1240.

Code I am using is Request.Browser.ScreenPixelsWidth

Does anyone knows why it returns 640 always or if there is another way for me to get the width of the browser upon page load?

like image 558
Bagzli Avatar asked May 24 '13 19:05

Bagzli


1 Answers

You need to populate a hidden field with Javascript (see this question for how to do that), and then send that field back to the server so that it's avaialble within ASP.NET.

ASP.NET is incapable of reading detailed browser information like that directly (you're talking about sending some very specific information from the client's browser to the ASP.NET server where your application is hosted, and there are a lot of problems involved with doing something like that).

See this similar, but less detailed, question:

Asp.Net Get Screen Width

like image 159
qJake Avatar answered Oct 04 '22 17:10

qJake