How Can I Center a Custom Auto Sized Window

2 posts, 0 answers
  1. Kori
    Kori avatar
    73 posts
    Member since:
    Dec 2008

    Posted 22 Mar 2012 Link to this post

    So, here's my scenario - in our app, the content of the window can very likely change, so what I've done is added the following to the pages being opened:

    function pageLoad() { fixWindow(); }
    function fixWindow() {
      // Fix the height to show the buttons in the right place.
      var oWnd = GetRadWindow();
      var contentHeight = $('#mainContent').height();
      var newHeight = contentHeight + 10;
      var windowWidth = oWnd.get_width();
      $('#popupWrapper').width(windowWidth - 75);
      var windowHeight = newHeight + 105;
      oWnd.set_height(windowHeight + "px");
      // if (oWnd != null) {
      // }

    This works great, except that if I then try to center the window every time, the window will remain open after a postback. How can I correct this so that the window gets centred and works normally?

    (Side note: We tried using the auto-size, but it never did a great job of keeping the window sized properly).

  2. Marin Bratanov
    Marin Bratanov avatar
    5922 posts

    Posted 26 Mar 2012 Link to this post

    Hello Kori,

    Take a look at the following help article which explains the most common reasons for problems with autosizing: See which of the points apply to your case and try employing the suggestions.

    As for the behavior you get after calling center() - how are you calling the  fixWindow() function? Is it only on the initial page load, or also after AJAX requests? I have seen similar behavior when center or moveTo() have been called after a postback but the RadWindow is already closed on the client (e.g. via the [x] button). If this is your case you can try adding a check - if(oWnd.isVisible());

    I tried your code in a simple page and things seem to be working fine with me: I am also attaching my test page here as a reference. Please examine it and see what is the difference in the setup that is causing the problem on your end.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top