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

Refreshing Parent RadWindow from RadWindow

3 Answers 207 Views
Window
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 19 Feb 2013, 05:06 PM
I've seen many posts that are similar to my issue but none of the suggestions work in my specific case.  I've already seen topics such as this one (http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid) and this one (http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html), however both of those solutions seem to be for when you are refreshing the entire page, not a Parent RadWindow from a Child RadWindow.

I have a master page that opens a RadWindow with a RadGrid.  This RadWindow is dynamically added so I do not know the sepecific ID because there might be other RadWindows that are open from the master page.  There is also a button on that page that executes code behind, then based on certain criteria, it opens another RadWindow through a RegisterStartupScript that calls the following JavaScript:

function GetRadWindow() {
                    var oWindow = null;
 
                    if (window.radWindow)
                        oWindow = window.radWindow;
                    else if (window.frameElement.radWindow)
                        oWindow = window.frameElement.radWindow;
 
                    return oWindow;
                }
 
function OpenModalRadWin(args) {
                    if (args == null)
                        alert("There was no URL supplied by the code.  Please contact the system administrator.");
                    else {
                        var RadWinManager = GetRadWindow().get_windowManager();
                        var newWin = RadWinManager.open(args);
                        newWin.setSize(250, 250);
                        newWin.set_modal(true);
                        setTimeout(function() { newWin.setActive(true); }, 0);
                    }
 
                    return false;
                }

The original window was opened in a similar JavaScript function except it is not modal.

The modal window takes user input and stores that in a database, then closes itself using GetRadWindow().Close(); in JavaScript.  I've tried to get the parent page (the first RadWindow) to either refresh or rebind the grid but all of the samples and other posts seem to not have a RadWindow within a RadWindow.  The JavaScript in the Parent RadWindow is not getting called by the Child RadWindow.  Below is some of the code commented out of what I've tried (it uses the same GetRadWindow() function as above:
function CloseWin() {
            //GetRadWindow().BrowserWindow.document.RefreshGrid();
            //GetRadWindow().get_contentFrame().contentWindow.RefreshGrid();
            GetRadWindow().Close();
            //GetRadWindow().BrowserWindow.RefreshGrid();
            //__doPostBack("<%=btnCancel.UniqueID %>", "");
            return true;
        }

I know that it isn't even calling the function on the Parent RadWindow because all I have it doing right now is calling alert('test'); and the alert is not coming up and the Child is not closing.

How do I call a function on a Parent RadWindow from a Child RadWindow?  More importantly, how do I only refresh the Parent RadWindow from a Child RadWindow without refreshing the entire page (master page).

3 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 20 Feb 2013, 03:51 PM
Hello Kyle,

I am not sure I completely understand the structure you have. My take is the following:
Master page + content page
     RadWindow1 + child page 1 that hosts RadWindow2
          RadWIndow2 + child page 2 that must refresh child page1

If this is the case calling the following from child page 2 will get you a reference to the window object of child page1:
GetRadWindow().BrowserWindow, or simply window.parent
You can further get a reference to RadWindow1 by
GetRadWindow().BrowserWindow.GetRadWindow() (assuming the the GetRadWindow() function is present in child page 1, of course).

If you have horizontal hierarchy, i.e. RadWindow2 is not nested within RadWIndow1 and they are both dynamic, you could use a custom field in the second popup's object to store a reference to the first (where I assume you are already familiar with the approach).

You can find attached a simple example of both scenarios. I hope it is helpful.

Regards,
Marin Bratanov
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.
0
Kyle
Top achievements
Rank 1
answered on 20 Feb 2013, 08:02 PM
Both windows are dynamically opened from the same RadWinManager.  There may also be several other windows open at the same time, but I'll use your terminology of MasterPage, RadWindow1, and RadWindow2.  I think the problem is that RadWindow2 can't find RadWindow1.
RadWindow1 is opened from the MasterPage using the following:
var WinManager = GetRadWindowManager();
WinManager.open(eventArgs.get_item().get_value());
where eventArgs.get_item().get_value() is a URL that is passed to the javascript function.

What was posted in the original post was how RadWindow2 is opened from RadWindow1.  Since all windows are opened dynamically, I cannot use the following from the page you and I both referenced because I do not have a Window name (it is dynamic).
var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");

I've tried using GetRadWindow().BrowserWindow.RefreshGrid();   from RadWindow2, but it isn't even getting called.  In fact, if I put that code before my GetRadWindow().Close();  and the .Close() doesn't even get called, so it isn't communicating with RadWindow1.  As of now on RadWindow1, all that I have is alert('test'); in the RefreshGrid() function so I know that the two RadWindows are communicating together (which they are not).
Could I add RadWindow1's reference to the args in the OpenModalRadWin() function.  The args variable is just a URL that is passed in that typically is something like anotherwebpage.aspx?p=123&PassedVar=1, so possibly add the value of GetRadWindow() to the variables being passed to the web page and use them on that end.  If so, how would I use it in RadWindow2 since I can't use getWindowByName() because RadWindow1 doesn't have a hardcoded name.
0
Kyle
Top achievements
Rank 1
answered on 20 Feb 2013, 08:30 PM
Your sample worked! Thanks!  I was able to use newWin.firstDialogReference = GetRadWindow(); in RadWindow1 right after the setTimeout for the open function and then could use the GetRadWindow().firstDialogReference.get_contentFrame().contentWindow.RefreshGrid(); line in my CloseWin function on RadWindow2.
Tags
Window
Asked by
Kyle
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Kyle
Top achievements
Rank 1
Share this question
or