Solved

Calculate height/width for a control

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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