ASP.NET C # get screen width in pixels

I am trying to get my browser width in pixels, but for some reason I am returning 640, my resolution is 1240.

The code I'm using is Request.Browser.ScreenPixelsWidth

Does anyone know why it always returns 640 or if I have another way to get the width of the browser when the page loads?

+4
source share
2 answers

You need to fill in the hidden Javascript field (see this question on how to do this) and then send this field back to the server so that it is accessible in ASP.NET.

ASP.NET is unable to directly read detailed information about the browser (you are talking about transferring some specific information from the client browser to the ASP.NET server where your application is located, and there are many problems involved in doing something like this).

See this similar but less detailed question:

Asp.Net Get Screen Width

+6
source

try it

 int x = (Request.Browser.ScreenPixelsWidth)*2-100; 

you can set the width according to your requirement

+3
source

Source: https://habr.com/ru/post/1482631/


All Articles