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

Adding a function to the "add_close" method in a nested Rad window opened using Radopen function.

1 Answer 279 Views
Window
This is a migrated thread and some comments may be shown as answers.
Shantnu Chaturvedi
Top achievements
Rank 1
Shantnu Chaturvedi asked on 06 Jan 2009, 10:09 PM
Hi,

I am trying to add a function to the close event of a nested radWindow.

There is a Main Window which has 'RadWindow1' inside it.
Then in the Loaded Page in RadWindow1, I have the following code, where I am opening a nested radWindow using radopen()

I can open the nested radWindow and run the application in the page loaded in it .
But I am getting this error in the application for the Close function --> "telerik Can't execute code from a freed script"

The function is right there and is so simple.
I can't figure out what is the issue as the function is in the parent (RadWindow1) and not the child.
So, if the parent (RadWindow1) is not terminated, how come the script is freed??

  • The Code is as follows:

     

<

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

body>

 

 


<
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 ShowNewRadWindow(stringUrl)

 

{

 

var oBrowserWnd = GetRadWindow().BrowserWindow;

 

 

var oWin = oBrowserWnd.radopen(stringUrl, null);

 

oWin.add_close(myAlert);

oWin.setActive(

true);

 

oWin.setSize (600, 500);

oWin.moveTo(100,100);

oWin.maximize();

alert(

"Please select the Errored records and Update them.");

 

}

 

 

 


function
myAlert()

 

{

alert(

"Window is Closing......");

 

}

function OnClientClose(sender, eventArgs)

 

{

 

var hiddenPostBackField = document.getElementById("PostBackSourceHiddenField");

 

 

hiddenPostBackField.value = "ChildPostBack"

 

 

 

 

 

alert(

"Window is Posting Back.");

 

 

 

 

 

DoPostBack();

 

 

 

alert(

"Window is closing.");

 

}

 

 

function DoPostBack()

 

{

__doPostBack(

'ctl00_ContentPlaceHolder1_RadWindow1','My Argument');

 

 

}

 

 

 

 

</

script>

 

 

 

 

 

<form id="form1" runat="server">

 

 

 

 

 

<div style="width:100%;">

 

<%

-------------------------------------------------------------------------------------------------------------%>

 

<%

-- Hidden field to check postback of the page from the Confirm Window. --%>

 

<%

-------------------------------------------------------------------------------------------------------------%>

 

 

<asp:HiddenField ID="PostBackSourceHiddenField" Value="SelfPostBack" runat="server" />

 

 

 

 

<%

-------------------------------------------------------------------------------------------------------------%>

 

 

.
.
.

 

 

<asp:Button ID="btnOpen_NestedradWindowConfirmInsert" Font-Bold="true" runat="server" Font-Size="small"

 

 

Text="Review new Window" ForeColor="red"

 

 

OnClientClick ="ShowNewRadWindow('./PopupPage.aspx');" />

 

 

.
.
--------------Other Code-----------------
.
.
.

 

 

</div>

 

 

 

 

 

</form>

 

</

body>

 

</

html>

 

 

 

 

 


1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 09 Jan 2009, 02:00 PM
Hi Shantnu,

I built up a test demo based on the provided code and I was able to reproduce the issue. However, it is not related to RadControls but it is a general ASP.NET problem which occurs when a script is executing while another script is running. There is link with the Google results of the problem below:

http://www.google.bg/search?hl=bg&q=Can%27t+execute+code+from+a+freed+script+&meta=

In your particular case, when you press the button, the page is started to be postbacked just after the client script is executed and also the attached handler is trying to execute - this causes the issue. In order to prevent the button to postback, you should return false as shown below:

 <asp:Button ID="btnOpen_NestedradWindowConfirmInsert" Font-Bold="true" runat="server" 
                Font-Size="small" Text="Review new Window" ForeColor="red" OnClientClick="ShowNewRadWindow('./PopupPage.aspx');return false;" /> 

After I modified my test demo in this manner, the error disappeared and it started working as expected. For your convenience I also attached my test project.

Greetings,
Svetlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Shantnu Chaturvedi
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or