Premium forums

Getting loaded window in document .ready

  • Simon
    Simon avatar

    05 Jul 2012 (Link to this post)

    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

  • Alex Gyoshev
    Alex Gyoshev avatar

    10 Jul 2012 (Link to this post)

    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!
  • Simon
    Simon avatar

    10 Jul 2012 (Link to this post)

    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
  • Alex Gyoshev
    Alex Gyoshev avatar

    11 Jul 2012 (Link to this post)

    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!

Read FAQ or see Kendo UI in action!

Launch Demos