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

Need to pass value to parant page when Radwindow close button is clicked

4 Answers 214 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Priyank
Top achievements
Rank 1
Priyank asked on 05 Feb 2014, 02:03 PM
Hi,

On my parent page I have defined OnClientClose() event:

function OnClientClose(oWnd, args) {
        var arg = args.get_argument();
        if (arg) {
            var prevSelectedItem = arg.prevSelectedItem;
            var radMenu = $find("<%=RadMenuInventoryActions.ClientID%>");
            var menuItem = radMenu.findItemByText(prevSelectedItem);
            if (menuItem) {
                menuItem.set_selected(true);
            }
        }
}

On the page which I’m showing on the Radwindow, I have a cancel button.  I’m using the following function as an event handler for its OnClientClick event.
function CancelAdd() {
                var prevSelectedItem = document.getElementById('PrevSelectItemHiddenField').value;
                var oArg = new Object();
                oArg.prevSelectedItem = prevSelectedItem;
                GetRadWindow().Close(oArg);
                     
}
I’m using the same function as an event handler for close (x) button of Radwindow.

$telerik.$(document).ready(function () {
          var oWnd = GetRadWindow();
          var closeButton = $telerik.$(".rwCloseButton", oWnd.get_popupElement());
          closeButton.click(function () {
               CancelAdd();
        });
});

The issue I'm facing is when I close the Radwindow using Cancel button I get the correct value on the parent page in arg.prevSelectedItem.
But When close the Radwindow using Close button I get arg.prevSelectedItem  as undefined.

Please let me know if there is a way to achieve this.

Thanks,
Priyank

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Feb 2014, 06:05 AM
Hi Priyank,

You can handle the OnClientBeforeClose event to pass the value from RadWindow page to Parent page. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadMenu ID="RadMenu1" runat="server">
    <Items>
        <telerik:RadMenuItem Text="Menu1">
        </telerik:RadMenuItem>
        <telerik:RadMenuItem Text="Menu2">
        </telerik:RadMenuItem>
    </Items>
</telerik:RadMenu>
<telerik:RadWindow ID="RadWindow1" runat="server" VisibleOnPageLoad="true" OnClientBeforeClose="Close">
    <ContentTemplate>
        <telerik:RadTextBox ID="RadTextBox1" EmptyMessage="Enter MenuItem" runat="server">
        </telerik:RadTextBox>
    </ContentTemplate>
</telerik:RadWindow>

JavaScript:
<script type="text/javascript">
    function Close(sender, args) {
        var text = $get("<%=RadTextBox1.ClientID %>")
        var menuitem = text.value;
        var menu = $find("<%=RadMenu1.ClientID %>");
        menu.findItemByText(menuitem).select();
    }
</script>

Thanks,
Shinu.
0
Priyank
Top achievements
Rank 1
answered on 06 Feb 2014, 06:39 AM
Hi Shinu,

I have already tried OnClientBeforeClose but it's not working.

The argument which I'm passing to parent page comes as undefined.

The sample code you have shared is different than what I'm trying to achieve.

I need to pass value through 'args' argument only.  
























































0
Marin Bratanov
Telerik team
answered on 06 Feb 2014, 11:15 AM
Hi Priyank,

You can use the OnClientBeforeShow event to call a function in your content page that will return the needed data: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html. Thus, regardless of the reason for the dialog to close, your function will execute and pass data back to the main page. You can then stop handling the OnClientClose event to avoid duplicating logic.
If there is some reason why you cannot do this, but you absolutely must use OnClientClose you can still use the OnClientBeforeClose event to call a function in the dialog page that will gather data and pass it to the close() method of the RadWIndow. Note that, at this point, the OnClientBeforeClose event will fire again, so you will need some logic (e.g., a flag) to prevent an infinite loop. You could reset the flag in the OnClientClose handler.


Regards,
Marin Bratanov
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Priyank
Top achievements
Rank 1
answered on 06 Feb 2014, 01:01 PM
Hi Marin,

Thanks a lot for suggesting a solution.

Eventually I got my job done by calling content page method from parent page in OnClientClose event like this:

function OnClientClose(oWnd, args) {
        var oWnd = GetRadWindowManager().getWindowByName("PartAddRadWindow");
        var prevSelectedItem = oWnd.get_contentFrame().contentWindow.GetPrevSelectedItem();
        var radMenu = $find("<%=RadMenuActions.ClientID%>");
        var menuItem = radMenu.findItemByText(prevSelectedItem);
        if (menuItem) {
            menuItem.set_selected(true);
        }
    }

Thanks,
Priyank

Tags
General Discussions
Asked by
Priyank
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Priyank
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or