Home / Community & Support / Knowledge Base / RadControls for ASP.NET AJAX / Window / Setting size in percent for the RadWindow

Setting size in percent for the RadWindow

Article Info

Rating: Not rated

Article information

Article relates to

 RadWindow for ASP.NET AJAX

Created by

 Marin Bratanov, Telerik

Created on

 5th of January 2012





HOW-TO:
Set the size of a RadWindow in percent.

DESCRIPTION:
The RadWindow supports its size in pixels only, as does any other window, e.g. in the operating system - changing the screen resolution or adding other elements in the viewport do not change the dimensions of the already existing windows. Therefore the RadWindow has the same behavior.


RadControls for ASP.NET AJAX


SOLUTION:
You can use a combination of the RadWIndow's client-side API and jQuery to calculate the needed dimensions in pixels from the available viewport and set them to the RadWindow. You should also handle the window.resize event in order to recalculate the size when the browser size changes:
get the viewport size:
var browserWidth = $telerik.$(window).width();
var browserHeight = $telerik.$(window).height();

change the RadWindow size where value is the size in percent you need:
oWnd.setSize(Math.ceil(browserWidth * value / 100), Math.ceil(browserHeight * value / 100));

You can then center the RadWindow:
oWnd.center();

This can be encapsulated in a function that will be called after the browser is resized. Note how the timeout is used to ensure that the handler is called only once, because older browsers throw the window.resize event numerous times which may result in poor performance without such an insurance:
$telerik.$(window).resize(function ()
{
    clearTimeout(TO);
    TO = setTimeout(sizeWindowInPercentage, 100);
});

Where TO is a global JavaScript variable that holds the timeout.

A simple page that shows the approach in action is attached to this post as well. Inside there are comments that explain in greater detail what the code does. This can be used as base for further extending this scenario, but you should keep in mind that it has its limitations - e.g. it cannot work for a restriction zone as you cannot handle the zone's size change, there is simply no such event. 

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.