This is a migrated thread and some comments may be shown as answers.
Initializing an Ajax loaded window
0 Answers 29 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerard
Top achievements
Rank 1
Gerard asked on 15 Apr 2012, 11:19 AM
Hi,

I have a window that is defined as follows:
@{Html.Telerik().Window()
      .Name("WindowName")
      .Title("Title")
      .ClientEvents(e => e.OnLoad("WindowName_onLoad"))
      .Width(850).Height(500)
      .Draggable(true).Resizable().Buttons(b => b.Maximize().Close())
      .Modal(true)
      .Visible(false)
      .Render();
}

I load it with an Ajax request ("_Content" is an action in my controller):
var wnd = $('#WindowName).data('tWindow');
wnd.ajaxRequest('_Content', {
    //...json parameters...
});
wnd.center().open();

Now, my problem is with the WindowName_onLoad method. I do some initialization of the contents of the window there. But if I do it synchronously, it doesn't work. The only solution I found is to do it after a certain delay:

Doesn't work:
function WindowName_onLoad() {
    // do initializations
};

Works:
function WindowName_onLoad() {
    window.setTimeout(function () {
        // do initializations
    }, 500);
};

Same issue happens if I don't use the onLoad event, but do the initializations after the open() call.

I'd like to understand why this works that way, and is there a better way to do it, as I don't find it very clean (it works with a timeout value of 500, but not 100, for example).

Thanks.




Tags
Window
Asked by
Gerard
Top achievements
Rank 1
Share this question
or