detecting client DPI setting in ASP.Net app

  • Thread starter Thread starter Ray Porter
  • Start date Start date
R

Ray Porter

I've figured out how to detect the client's screen width and height but is
there anyway to do the same for the client DPI setting?

I can do this in a Delphi/Intraweb isapi app but I haven't found how to do
it in C#/ASP.Net.

Thanks,
=================================
Ray Porter
Information Systems
Applications Development Manager
Division of University Advancement
University of North Carolina at Chapel Hill
Phone: (919) 259-9389
Fax: (919) 843-3314
Pager: (919) 216-4218

(e-mail address removed)
http://www.unc.edu/~dragon

Meddle not in the affairs of dragons for thou
art crunchy and taste good with ketchup
 
1. I wonder how you did it with Delphi/Intraweb isapi app

My guess in order to detect DPI you need some executable to sit on the
clients computer
The way it's usually done is using Flash. It's some executable that is
sitting on clients computer but lucky for us almost everyone has it.


George.
 
Delphi with IntraWeb allows you to program, for the most part, just as you
would for a desktop app. Intraweb automatically generates any client-side
Javascript code needed to make it all work.

I found the solution myself for Visual Studio. I finally, after hours of
searching, found a site providing fairly complete documentation for the
Javascript "screen" object that exposes various attributes of the client,
including width, height and dpi. The solution is simply to write a little
Javascript snippet in the aspx file to get the necessary values from the
screen object then stick those values in corresponding hidden inputs on the
form. Since I couldn't find a complete, intelligible example anywhere (all
partial snippets), I'll include it here for anyone else who might need it.
I haven't looked closely at the IntraWeb javascript but I imagine it does
the samething -- it just does it for you.

In your C# code, just read Request.Form["ScreenWidth"], etc.

<script type="text/javascript" language="javascript">
var width = screen.width;
var height = screen.height;
var dpi = screen.deviceXDPI;
window.onload = function() {
document.getElementById("ScreenWidth").value = width;
document.getElementById("ScreenHeight").value = height;
document.getElementById("ScreenDPI").value = dpi;
}
</script>

<input type="hidden" name="ScreenWidth" />
<input type="hidden" name="ScreenHeight" />
<input type="hidden" name="ScreenDPI" />

Ray
 
Back
Top