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

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

10 Answers 553 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simone
Top achievements
Rank 1
Simone asked on 02 Feb 2012, 05:32 PM
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.

10 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Feb 2012, 06:01 PM
Hello,

please check below link.

Window / Returning Values from a Dialog

Thanks,
Jayesh Goyani
0
Simone
Top achievements
Rank 1
answered on 02 Feb 2012, 06:07 PM
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.




0
Simone
Top achievements
Rank 1
answered on 02 Feb 2012, 06:13 PM
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
0
arnaud
Top achievements
Rank 1
answered on 29 Jun 2012, 08:03 AM
Nice Simone.
Thank you, it was what I was looking for.

0
Robert
Top achievements
Rank 1
answered on 03 Oct 2012, 08:29 PM
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.
0
Marin Bratanov
Telerik team
answered on 04 Oct 2012, 07:48 AM
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.
0
Robert
Top achievements
Rank 1
answered on 04 Oct 2012, 02:48 PM
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!
0
Marin Bratanov
Telerik team
answered on 05 Oct 2012, 07:04 AM
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.
0
Jey
Top achievements
Rank 1
answered on 01 Feb 2019, 11:58 PM
What was the solution? Please advise
0
Marin Bratanov
Telerik team
answered on 02 Feb 2019, 02:03 PM
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.
Tags
Window
Asked by
Simone
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Simone
Top achievements
Rank 1
arnaud
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Marin Bratanov
Telerik team
Jey
Top achievements
Rank 1
Share this question
or