This is a migrated thread and some comments may be shown as answers.

[Solved] Why is ther no Window.OnLoadCompleted event?

1 Answer 29 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rainer
Top achievements
Rank 1
Rainer asked on 06 Oct 2011, 11:43 AM
Hi all,

I just wonder if there is any way to get his scenario to work:

I have a page with a hidden Window that loads a PartialView from the Controller: This partial view actually returns a list of items, all of them with a particular attribute data-id holding the item id...

<% Html.Telerik().Window()
            .Name("SelectionWindow")
            .Visible(false)
            .ClientEvents(
              events =>
                events.OnLoad("onLoad"))
            .LoadContentFrom("GetObjects") // preload...
            .Render();
    %>

Unfortunately this partial view does not know that it runs inside a window and therefore does not do anything but rendering that item list. Now this is the reason why I need to inject that specific behavior from the outside. All I wanted to do is to attach a click handler to all the items so they perform exactly what I want them to do:

function onLoad(e) {
   $('span[data-id]')
    .click(function (e) {
        e.preventDefault();
        var id = $(this).data('id'); // get the selected id
        var url = '<%= Url.Action("CreateChildObject") %>';
        $('#ObjectDetailsWindows').data('tWindow').ajaxRequest(url, {objectID: id }); // load the details form into another window
        $('#ObjectDetailsWindows').data('tWindow').center().open();
        $('#SelectionWindow').data('tWindow').close();
    });
}

And here comes the problem: This code only works when I delay the onLoad function in the JS-Debugger - obviously the Window has not yet loaded its content when the onLoad event is fired.

Isn't there a way to pass that Window control a Callback which is called when the request is finished? I could also use that .ajaxRequest method but do not find any documentation whether I can pass a callback handler or not.

Any help is greatly appreciated. Thanks!

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 11 Oct 2011, 08:01 AM
Hello Rainer,

The "refresh" event is triggered when the AJAX request finishes loading, so the following should work in your case: instead of
events.OnLoad("onLoad"))
use
events.OnRefresh("onLoad"))

Greetings,
Alex Gyoshev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Window
Asked by
Rainer
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or