Detecting a Client’s screen resolution in ASP.NET

23 Feb

Ref:http://devcity.net/Articles/64/1/screenresolution.aspx

Default.aspx Code:

public void Page_Load(Object sender, EventArgs e){

if (Session[“ScreenResolution”] == null) {
// Session variable is not set
// Redirect to the screen resolution detection script
Response.Redirect(“detectscreen.aspx”);
} else {
// Session variable is set
// Display it on the page
screenresolution.Text = Session[“ScreenResolution”].ToString();
}
}

detectScreen.aspx Code:

<script runat=”server” language=”C#”>

public void Page_Load(Object sender, EventArgs e){

if (Request.QueryString[“action”] != null) {
// store the screen resolution in Session[“ScreenResolution”]
// and redirect back to default.aspx
Session[“ScreenResolution”] = Request.QueryString[“res”].ToString();
Response.Redirect(“cat.aspx”);
}
}
// JavaScript code below will determine the user screen resolution
// and redirect to itself with action=set QueryString parameter

</script>
<script language=”javascript”>
res = “&res=”+screen.width+”x”+screen.height+”&d=”+screen.colorDepth
top.location.href=”detectscreen.aspx?action=set”+res
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: