关闭一个radwindow后如何调用客户端javascript函数

时间:2016-08-05 05:48:39

标签: javascript asp.net telerik

在aspx page1中我有一个按钮。我点击按钮,打开一个在aspx page2中实现的radwindow。在radwindow中,我输入一些数据,然后单击“保存”按钮。它调用服务器端方法,然后关闭radwindow。关闭radwindow后,它应该触发page1的方法。怎么做到这一点?

从第1页打开radwindow的代码:

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

关闭第2页的radwindow的代码

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


        }

2 个答案:

答案 0 :(得分:1)

我尝试过测试你的代码,但我不能。我在示例中看到的是,radwindow是以这种方式声明的,而不是像您尝试的那样动态声明。

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

我建议你查阅文档,那里有一些例子。

OnClientClose的演示:

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

OnClientClose的文档:

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

答案 1 :(得分:1)

使用RadWindow的客户端API附加OnClientClose处理程序: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);

请注意,refreshGrid函数必须与打开的RadWindow位于同一上下文(页面)中。如果不是,请查看以下代码库项目,了解如何将它们绑定在一起:http://www.telerik.com/support/code-library/creating-parent-child-relationships-between-radwindows-and-passing-data-between-them