John
John

Reputation: 495

Asp.Net Get Screen Width

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

Upvotes: 6

Views: 61816

Answers (4)

bilal chaudhari
bilal chaudhari

Reputation: 77

Use code below

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

Upvotes: 3

Yitzhak Weinberg
Yitzhak Weinberg

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

flap13
flap13

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

TGlatzer
TGlatzer

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

Related Questions