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

5 posts, 0 answers
  1. Priyank
    Priyank avatar
    13 posts
    Member since:
    Nov 2013

    Posted 05 Feb 2014 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2014 in reply to Priyank Link to this post

    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.
  3. Priyank
    Priyank avatar
    13 posts
    Member since:
    Nov 2013

    Posted 06 Feb 2014 Link to this post

    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.  
























































  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4614 posts

    Posted 06 Feb 2014 Link to this post

    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.
  5. Priyank
    Priyank avatar
    13 posts
    Member since:
    Nov 2013

    Posted 06 Feb 2014 in reply to Marin Bratanov Link to this post

    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

Back to Top