Asp.Net Get Screen Width

How can I get the screen width on the server side in an Asp.net (C#) project?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Place this on your form:

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

This is onload script:

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

This is server side code:

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

Method 2

You could read it with javascript and submit the results to the server.
A server-side-only solution can not exist, since html does not submit such data automatically in requests.

Method 3

Use code below

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

Method 4

to get the Characters

Request.Browser.ScreenCharactersWidth
Request.Browser.ScreenCharactersHeight

to get the Resolution

you need to send the data from client side with javascript or jquery
i use this code its good the work

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x