Karts
Karts

Reputation: 85

How to call a client-side javascript function after closing a radwindow

In aspx page1 I have a button. I click on the button, it opens a radwindow which is implemented in aspx page2. In the radwindow I enter some data and click on save button. It calls server side method and then closes the radwindow. After closing the radwindow, it should fire page1's method. How to achieve this?

Code to open the radwindow from page1:

      function btnAddNewImage_click() {
        debugger;
        var hdn_PatientId = document.getElementById("<%=hdn_PatientId.ClientID %>").value;
        var selectedEncounterId = document.getElementById("<%=hdn_EncounterId.ClientID %>").value;
        var oWnd = radopen("../Admin/Encounter/PopUps/UploadImages.aspx?EncounterId=" + selectedEncounterId + "&PatientId=" + hdn_PatientId, "rwDialog");
        oWnd.SetTitle("Upload Image");
        oWnd.SetSize(600, 350);
        oWnd.Center();
        //oWnd.add_close("refreshGrid");
        oWnd.OnClientClose = "refreshGrid"; // Not working
        return false;

    }

Function to fire after radwindow is closed:

function refreshGrid(sender, eventArgs) {
        debugger;
        alert("in refreshgrid");
        var selectedEncounterId = document.getElementById("<%=hdn_EncounterId.ClientID %>").value;
        loadImagesProgressNotes(selectedEncounterId, "Current");
    }

Code to close the radwindow in page2

RadScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "javascript:returnToParent();", true);     
function returnToParent() {
            debugger;
            //get a reference to the current RadWindow               
            var oWnd = GetRadWindow();                
            oWnd.close();


        }

Upvotes: 2

Views: 1901

Answers (2)

rdmptn
rdmptn

Reputation: 5601

Use the client-side API of the RadWindow to attach the OnClientClose handler: http://docs.telerik.com/devtools/aspnet-ajax/controls/window/client-side-programming/radwindow-object#methods-for-modifying-client-side-event-handlers-dynamically.

var oWnd = radopen();
oWnd.add_close(refreshGrid);

Note that the refreshGrid function must be in the same context (page) as the RadWindow that is opened. If they are not, review the following code library project to see how to tie them together: http://www.telerik.com/support/code-library/creating-parent-child-relationships-between-radwindows-and-passing-data-between-them

Upvotes: 2

nsantana
nsantana

Reputation: 2050

I tried test your code, but I can't. What I saw in the examples is that the radwindow is declared in this way, not dynamically as you are trying.

<telerik:RadWindow RenderMode="Lightweight" runat="server" 
  ID="RadWindow1" OnClientClose="OnClientCloseHandler"
  NavigateUrl="dialog-page.aspx" VisibleOnPageLoad="true">   
</telerik:RadWindow>

I recommend that you consult the documentation, there are some examples there.

Demonstration of OnClientClose:

https://demos.telerik.com/aspnet-ajax/window/examples/clientsideevents/defaultcs.aspx

Documentation of OnClientClose:

http://docs.telerik.com/devtools/aspnet-ajax/controls/window/client-side-programming/events/onclientclose

Upvotes: 2

Related Questions