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

I can’t call the JavaScript function of the parent page.

2 Answers 130 Views
Window
This is a migrated thread and some comments may be shown as answers.
Vinix
Top achievements
Rank 1
Vinix asked on 07 Sep 2008, 03:03 PM
I want to call the JavaScript function after the rad window close, but it does not work.
Following is my codes.
Please help me to solve the problem.

Thank you very much.
http://ppt.cc/CVlG

parent page

function OpenRadWindow() {  
   var oWnd = radopen('WebForm1.aspx'null);  
 
}  
function TestFunction() {  
   alert("Test");  
}  
 
<asp:ScriptManager ID="ScriptManager1" runat="server">  
</asp:ScriptManager> 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">  
</telerik:RadWindowManager> 
<br /> 
<asp:Button ID="Button1" runat="server" Text="Button" /> 
protected void Page_Load(object sender, EventArgs e)  
{  
   this.Button1.OnClientClick = "OpenRadWindow();return false;";  

rad window page
 //This code is used to provide a reference to the radwindow "wrapper"  
 function GetRadWindow() {  
    var oWindow = null;  
    if (window.radWindow) oWindow = window.radWindow;   
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;   
       return oWindow;  
}  
 
function CallFunctionOnParentPage(fnName) {  
   var oWindow = GetRadWindow();  
   if (oWindow.BrowserWindow[fnName] &&   
       typeof (oWindow.BrowserWindow[fnName]) == "function") {  
      oWindow.BrowserWindow[fnName](oWindow);  
      oWindow.close();  
   }  
<asp:Label ID="InjectScript" runat="server"></asp:Label> 
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> 
 
//We do some server-side processing and we decide which function to call  
string fnName = "TestFunction()";  
InjectScript.Text = "<script>CallFunctionOnParentPage('" + fnName + "')</" + "script>";  
 

2 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 08 Sep 2008, 12:15 PM
Hi Liu Pei-Sen,

You need to set the name of the function only in the codebehind:
string fnName = "TestFunction";

By the way, you can achieve the same functionality by setting the name of the function in RadWindow's OnClientClose eventhandler
e.g.
OnClientClose="TestFunction".



Best wishes,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vinix
Top achievements
Rank 1
answered on 09 Sep 2008, 04:07 AM
It works.
Thank you very much.
Tags
Window
Asked by
Vinix
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Vinix
Top achievements
Rank 1
Share this question
or