detecting client DPI setting in ASP.Net app

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
 
G

George

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.
 
R

Ray Porter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top