Solved

Calculate height/width for a control

Posted on 2007-11-24
3
468 Views
Last Modified: 2012-06-21
Hi,

I have a control on my aspx page, it has a Height and Width property that I want to set on Page_Load. The height and width should correspond to the browser windows size (depending on users resolution) and therefore the control should fill the entire browser window (without the scroll bars appearing when the browser is maximised). How can I calculate the height and width for this control? There should be no whitespace on the page, just the whole control filling the page.

Thank you very much for any help.
0
Comment
Question by:Programmer_to_be
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 125 total points
ID: 20342654
The server doesn't know the size of the browser window. If you want that information available to the server, you have to use a Javascript in a page that sends that information back to the server in a request, so that you can use it when you create the next page. Also, this only gives information about the size at the moment when the request is sent, the user can resize the window at any time.

I suggest that you use css to specify the size of the control, so that it will resize automatically according to the window size. Something like:

html, body { width: 100%; height: 100%; overflow: hidden; }
body { margin: 0; padding: 0; }
.TheControl { width: 100%; height: 100%; }

The width and height on the html and body tag is needed to make them fill the browser window. The overflow makes sure that there are no scroll bars.

Specifying margin and padding makes sure that there is no space between the control and the window edges.

You use the TheControl class on your control by specifying it as class name. For an html control you use class="TheControl", for a web control you use CssClass="TheControl".

Specifying the size of the control that way makes it the size of it's parent control. If you have a form around the control you may also need:

form { margin: 0; width: 100%; height: 100%; }
0
 

Author Closing Comment

by:Programmer_to_be
ID: 31410763
A very well explained solution.
0
 

Author Comment

by:Programmer_to_be
ID: 20346641
Thank you GreenGhost for taking the time out to explain the solution. It worked a charm!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question