Reputation: 495
How can I get the screen width on the server side in an Asp.net (C#) project?
Upvotes: 6
Views: 61816
Reputation: 77
Use code below
int width = (Request.Browser.ScreenPixelsWidth) * 2 - 100;
int height = (Request.Browser.ScreenPixelsHeight) * 2 - 100;
Upvotes: 3
Reputation: 2572
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;
Upvotes: 3
Reputation: 411
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"];
Upvotes: 11
Reputation: 6258
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.
Upvotes: 9