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

Getting loaded window in document .ready

3 Answers 266 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 05 Jul 2012, 02:56 PM
Hello,

I want to pass a RecordID to a child Window and then I want that child window to use this RecordID in the document ready function to load the rest of the form.

This is how I call the child window:
window.kendoWindow({
    content: {
        url: "order.aspx",
        data: {
            RecordID: 1234
        }
    }
});

On the server side, I'm able to set the RecordID in a Textbox (let's call it tbRecordID).  This is where it gets more complicated.

Usually, in order to get the tbRecordID value, you whould just get it directly using it's id in the order.aspx document ready function: 
$(document).ready(function () {
     myRecordID =$("#tbRecordID").val();
     //load components for myRecordID...
    
});

However, this won't work if you allow users to open more than one instance of the same window  (ex: lets say the the user want to see order 1, 17 and 53 side by side) because this would create an id conflict.

So the only option I can see for now is to add a class to the tbRecordID and the refer to it from the "loaded" window with a jQuery search.
$(document).ready(function () {
      var targetWindow = //I need a way to get a reference to the target window
 
      var myRecordID = targetWindow.find(".RecordIDClass").val();
 
      //load with myRecordID
 
 
});

So, is there a way to get a reference to the window that is behing loaded?

Or maybe there is an other way to achieve what I'm trying to do in the document .ready function?

Best regards,

Simon

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 10 Jul 2012, 12:30 PM
Hello Simon,

Since the code is in order.aspx, you can simply render it dynamically from the server:

var myRecordID = <%= recordId %>; 

Greetings,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Simon
Top achievements
Rank 1
answered on 10 Jul 2012, 01:12 PM
Hello Alex,

Indeed, this would solve the RecordID problem but without the window reference, I won't be able to load components within the new window.

Regards,

Simon
0
Alex Gyoshev
Telerik team
answered on 11 Jul 2012, 06:02 AM

You can render an element that contains the record id in the partial view, i.e.:

<div id="record-<%= RecordID %>"></div>

And then get the window through it:

var windowObject = $("#record-<%= RecordID %>").closest("[data-role=window]").data("kendoWindow");

Kind regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Window
Asked by
Simon
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Simon
Top achievements
Rank 1
Share this question
or