Asp.Net Get Screen Width

How to get server side screen width in Asp.net (C #) project?

+2
source share
4 answers

You can read it using javascript and send the results to the server.
A server-side solution cannot exist since html does not automatically send such data in requests.

+6
source

Put this on your form:

<input type="hidden" value="" name="clientScreenHeight" id="clientScreenHeight" /> <input type="hidden" value="" name="clientScreenWidth" id="clientScreenWidth" /> 

This is an onload script:

 $(document).ready(function () { $("#clientScreenWidth").val($(window).width()); $("#clientScreenHeight").val($(window).height()); }); 

This is the server side code:

 string height = HttpContext.Current.Request.Params["clientScreenHeight"]; string width = HttpContext.Current.Request.Params["clientScreenWidth"]; 
+5
source

to get characters

 Request.Browser.ScreenCharactersWidth Request.Browser.ScreenCharactersHeight 

to get permission

you need to send data from the client side using javascript or jquery i use this code, it works well

 var ScreenPixelsHeight = window["innerHeight"]; var ScreenPixelsWidth = window["innerWidth"]; var JSLink = "http://www + "&ScreenPixelsHeight="+ScreenPixelsHeight+ "&ScreenPixelsWidth="+ScreenPixelsWidth; 
+2
source

Use the code below

 int width = (Request.Browser.ScreenPixelsWidth) * 2 - 100; int height = (Request.Browser.ScreenPixelsHeight) * 2 - 100; 
+1
source

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


All Articles