Solved

Calculate height/width for a control

Posted on 2007-11-24
3
466 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now