Getting value from RadWindow when user presses [X] close window button

11 posts, 0 answers
  1. Simone
    Simone avatar
    34 posts
    Member since:
    Mar 2011

    Posted 02 Feb 2012 Link to this post

    Using javascript, 

    I need to get the value of a TextBox that's in a RadWindow when the user presses X Close button:

            function OnClientBeforeClose(sender, args) {
    ???how do I get the RadWindow1 TextBox1 value ???
            }

    Reason is, I need to refresh the parent page based on that value after the user hits the X Close button.

    How do I do that?
    Thanks.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 02 Feb 2012 Link to this post

    Hello,

    please check below link.

    Window / Returning Values from a Dialog

    Thanks,
    Jayesh Goyani
  3. Simone
    Simone avatar
    34 posts
    Member since:
    Mar 2011

    Posted 02 Feb 2012 Link to this post

    I just figured out how to do this.
    I'm posting the code here, it might help someone.

    I looked up the client script reference, and The RadWindow has a property called "argument" , and that was the key!
    I can pass in the argument to the parent window using this.


    //Client Window JavaScript:

            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
            function SetArgumentValue(arg) {
                var oWindow = GetRadWindow();
                oWindow.argument = arg;
            }

    //Client Window C#
            protected void OnMyEvent (object sender, EventArgs args)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ReloadRepSessions", "SetArgumentValue(" + "'ThisIsMyArgument'" + ");", true);
            }

    //Parent Page Javascript

            function OnClientBeforeClose(oWnd, args) {
                var oWnd = $find("<%= RadWindow1.ClientID %>");
                var arg = oWnd.argument;

    ...
    //reload control on parent
    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest(arg);
    ....
            }

    <telerik:RadWindow  .... OnClientBeforeClose="OnClientBeforeClose"

    //Parent Page c# code
            protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
            {
                switch (e.Argument)
                {
    case "ThisIsMyArgument" ....


    Hope this helps someone later.




  4. Simone
    Simone avatar
    34 posts
    Member since:
    Mar 2011

    Posted 02 Feb 2012 Link to this post

    Thanks Jayesh, but that example uses the arguments passed on "OnClientClose" and that was not what I was looking for.

    What I was looking for was a way to get the argument before the window closes, when the user presses the X close button.

    But I figured out a solution for this.

    Thanks,
    Simone
  5. arnaud
    arnaud avatar
    105 posts
    Member since:
    Jul 2008

    Posted 29 Jun 2012 Link to this post

    Nice Simone.
    Thank you, it was what I was looking for.

  6. John
    John avatar
    25 posts
    Member since:
    Jan 2011

    Posted 03 Oct 2012 Link to this post

    Thanks Simone this does almost everything I need.  I just can't determine how you are triggering the OnMyEvent event you have (which sets the argument I need to retrieve on the parent page) to occur when the user clicks the X to close the RadWindow?

    Essentially on my parent page I have a RadEditor, which allows a RadWindow to be created for full screen editing on a child page, and I would like it to persist this data to the parent page when the user closes this RadWindow. 

    I have it sending the data to the child page and loading the content in the RadEditor there no problem, and I can pass back the data to the parent page if the user clicks the Save button I have for them in the RadEditor toolbar, but no event seems to fire that allows me to save the content when the user closes via the RadWindow status bar.
  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4752 posts

    Posted 04 Oct 2012 Link to this post

    Hi John,

    I can suggest two ways to get this working:

    1) remove the Close behavior of the RadWindow so that the users have to go  through your custom code and buttons: http://demos.telerik.com/aspnet-ajax/window/examples/behaviors/defaultcs.aspx.

    2) Use the OnClientClose or OnClientBeforeClose event to call a function in the child page that will get the content you need:
    http://demos.telerik.com/aspnet-ajax/window/examples/clientsideevents/defaultcs.aspx?product=window
    http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html

    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.
  8. John
    John avatar
    25 posts
    Member since:
    Jan 2011

    Posted 04 Oct 2012 Link to this post

    Hi Marin thanks. 

    This pointed me in the right direction and was able to get it working using method 2 with something like this:

    Child Page

    <script type="text/javascript">
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
     
        // return current editor content
        function GetEditorContent() {
            var content = $find("<%=RadChildEditor.ClientID%>").get_html(true);
     
            return content;
        }
    </script>

    Parent Page

    <script type="text/javascript">
           function GetRadWindow() {
           var oWindow = null;
           if (window.radWindow) oWindow = window.radWindow;
           else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
           return oWindow;
           }
     
           function SetEditorContent(content) {
           $find("<%= RadEditorParent.ClientID %>").set_html(content);
           }
     
           function OnClientBeforeClose(oWnd, args) {
           var oWnd = $find("<%= DialogWindow.ClientID %>");
           var contentWindow = oWnd.get_contentFrame().contentWindow;
            
           if (contentWindow && contentWindow.GetEditorContent) {
               window.setTimeout(function () {
               SetEditorContent(contentWindow.GetEditorContent());
               }, 500);
           }
           }
    </script>

    Thanks for the assistance!
  9. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4752 posts

    Posted 05 Oct 2012 Link to this post

    Hi John,

    I am glad that you were able to resolve the situation. I would like to give you a few pointers

    - the GetRadWindow() function is meaningful only in the context of a page inside a RadWIndow, so it is needed only in the content page where the  GetEditorContent() is declared.

    - the first argument the OnClientBeforeClose handler receives is the RadWindow instance, so you do not need the $find() call to get a reference to the RadWindow.


    All the best,
    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.
  10. Jey
    Jey avatar
    1 posts
    Member since:
    Sep 2014

    Posted 01 Feb in reply to Simone Link to this post

    What was the solution? Please advise
  11. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4752 posts

    Posted 02 Feb Link to this post

    Hi Jey,

    Maybe the following example will give you a few ideas: https://www.telerik.com/support/code-library/creating-parent-child-relationships-between-radwindows-and-passing-data-between-them.

    If you have a more concrete question, I'd suggest opening a separate thread or a private support ticket where you could add some details on the problem you are facing so you could get a more concrete answer.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top