Get browser window size from C# codebehind

J

Just D.

How can we get the browser window size from C# codebehind? What's the
easiest way to do that?

Just D.
 
D

darrel

How can we get the browser window size from C# codebehind? What's the
easiest way to do that?

You'd have to grab the information client side with javascript and send it
back to the server on postback.

-Darrel
 
J

Just D.

HI Darrel,

I will try to explain. The significant headache is to create a universal
interface fitting any screen size. If the user resizes the browser it's a
good idea to adopt the interface to its needs. I'm trying to replace some of
the rulers made by JPG/GIF images by something more flexible like panels, or
simply drawing on the form, it's possible but I need to know the real size
of current frame where I'm drawing on. That's why this question appeared.
From one size I could use something standard like fill the frame, etc. but
if I need to modify the color using the position of the line it's harder, I
need to know the line length to draw it correctly.

If anybody can propose anything more efficient it would be nice, but I'm
currently seeing only this solution.

If I could get the browser window/frame size while the user resizes it, then
it would solve these problems because it's possible to recreate the
graphics, it's fast.

Another one method is - to use JAVA scripts to draw on the remote side
directly without any post backs. More efficient way, but is it really easier
for programming?

Just D.
 
D

darrel

I will try to explain. The significant headache is to create a universal
interface fitting any screen size. If the user resizes the browser it's a
good idea to adopt the interface to its needs. I'm trying to replace some of
the rulers made by JPG/GIF images by something more flexible like panels, or
simply drawing on the form, it's possible but I need to know the real size
of current frame where I'm drawing on. That's why this question appeared.
From one size I could use something standard like fill the frame, etc. but
if I need to modify the color using the position of the line it's harder, I
need to know the line length to draw it correctly.

Consider using CSS for this. You can do what you are talking about, but it's
typically much easier to just use CSS.

For instance, if you have a rule, you can just assign a border to a div set
to 100% width, and it will resize as needed.

Redrawing the interface on postback based on viewport size is certainly
doable, but not really sure if it's worth the effort.

-Darrel
 
W

William F. Robertson, Jr.

I don't think you can even get the browser size beyond using the client side
function getBoundingClientRect(), but I haven't had any luck really
determining the size of the browser. There is also a screen.width,
screen.height property that will return the screen resolution the browser is
on.

If you do find a way, you will need to send this information back to the
server, so you can do something with it. Plus, what will stop your user
from resizing their browser window?

HTH,

bill
 
J

Just D.

Thanks, William,

I found a better way - all controls are using %% instead of pixels and it
works just great and on the client side. Yes, it brings some disadvantages
during development, but it price is good - the convenient resizable
interface.

Just D.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top