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

OnClientClose Postback Fires On Page Load

7 Answers 364 Views
Window
This is a migrated thread and some comments may be shown as answers.
D O
Top achievements
Rank 1
D O asked on 23 Sep 2009, 11:41 PM
Hi There

I have a master page and content page.  I would like to call a function in code behind of the 'parent' page when the radwindow is closed.  My problem is that when I load the parent page the first time, the postback occurs when I specify OnClientClose="__doPostBack()" - even before I have opened the RadWindow and closed it.  What am I doing wrong?  I want it to only fire once the user has opened the RadWindow and closes it.

Here's my code:

<%

@ Page Language="VB" MasterPageFile="~/MasterHRJ001.master" AutoEventWireup="false" CodeFile="tester.aspx.vb" Inherits="tester" title="Untitled Page" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<

 

asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 

 

<asp:linkbutton id="Test" runat="server" text="Create Text file" onclick="Test_Click" />

 

 

 

 

 

 

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" Skin="Black"

 

 

DestroyOnClose="true"

 

 

OnClientClose="__doPostBack('ctl00$ContentPlaceHolder1$Test','')"

 

 

>

 

 

<Windows>

 

 

<telerik:RadWindow

 

 

id="RadWindow1"

 

 

runat="server"

 

 

showcontentduringload="False"

 

 

width="900px"

 

 

height="550px"

 

 

 

 

title="Telerik RadWindow" Modal="true" VisibleStatusbar="false" Skin="Black" style="display:none;" InitialBehavior="None" Left="" NavigateUrl="" Top="">

 

 

</telerik:RadWindow>

 

 

 

 

 

 

</Windows>

 

 

</telerik:RadWindowManager>

 

 

 

<script type="text/javascript">

 

 

//<![CDATA[

 

 

 

function openRadWin5()

 

{

radopen(

"business-sol-surveys.aspx?cont=5","RadWindow1");

 

}

 

 

//]]>

 

 

</script>

 

 

 

<a id="A1" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Test','')">Testing to see if the postback works</a>

 

 

<

 

a id="A2" href="javascript: openRadWin5()">Open RAD Win 5</a>

 

 

</

 

asp:Content>

 

7 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 24 Sep 2009, 09:01 AM
Hello D O,

The OnClientClose event handler (and all others like OnClientShow, OnClientPageLoad etc.) accepts the name of the function (that should be called only). What I suggest is to put your JavaScript code in a separate function and set the name of that function in the event handler,
e.g.
OnClientClose="InvokePostBack"
....
function InvokePostBack()
{
   // your code here
}




Best wishes,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alain
Top achievements
Rank 1
answered on 09 May 2011, 07:02 PM
I have the same issue. The OnClientClode is raised at every page load, making an infinite loop.

Wrapping in a function didn't fix it.
0
Georgi Tunev
Telerik team
answered on 12 May 2011, 12:16 PM
Hi David,

The solution for D O's case was to make sure that the OnClientClose property (and any other client event properties - OnClientShow / OnClientPageLoad / etc.) contain the name of the function only - e.g.

OnClientClose="MyClosingFunction"

If this is not your case, please open a support ticket and send a small sample that reproduces the problem so we can check it.



All the best,
Georgi Tunev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Pat Huesers
Top achievements
Rank 1
answered on 21 Jan 2012, 12:19 AM
Can we pass a parameter to a javascript function from the OnClientClose event?

Something like this for example:

function

 

 

testalert(foo) {

 

alert(foo);

}

 

 

 

<telerik:RadWindow ID="rwTestWindow" runat="server" Width="1000px"

 

 

 

Behaviors="Close, Move, Reload" KeepInScreenBounds="True" Height="450px"

 

 

 

Title="Test Window" OnClientClose="testalert('TEST')" >

For whatever reason, testalert('TEST') is getting called on PAGE_LOAD. It executes successfully and displays an alert box.  then when I open the rwTestWindow and click the close button, which fires the OnCLientClose event, I get the error:  Microsoft JScript runtime error: Object doesn't support this property or method

If I do as you say, and leave only the function name in place..   like this

 

<telerik:RadWindow ID="rwTestWindow" runat="server" Width="1000px"

 

 

 

Behaviors="Close, Move, Reload" KeepInScreenBounds="True" Height="450px"

 

 

 

Title="Test Window" OnClientClose="testalert" >

Then, everything works like it should.  So, Can we use parentheses when calling our javascript functions?  And Can we pass parameters to those functions?  

Suggestions?  Thanks.



0
Marin Bratanov
Telerik team
answered on 23 Jan 2012, 04:45 PM
Hello Pat,

When adding handlers to the client-side events of th RadControls you only need to pass the JavaScript function's name, without the parentheses. They cause it to be executed (as this is their function) as soon as they are parsed, which happens when the controls are being instantiated while the page loads.

What you can do to pass another argument (apart from the two default ones the function already receives) - option 1 is to use a global JavaScript variable to store the needed information. If this does not fit your needs option two is to use the third approach from this code-library article to pass a custom argument.


Regards,
Marin
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
Pat Huesers
Top achievements
Rank 1
answered on 23 Jan 2012, 06:26 PM
Thank you for your reply Marin.  The information was helpful, but I'm not sure it entirely solves my problem.

The commandargument and commandname properties are not available for a Rad window, so I cannot access the information I need that way using the get_commandname or get_commandargument functions.

I am curious about the global javascript variable and how that would be implemented.   Take my simple example: 

function
testalert() {

    alert(foo);

}

<telerik:RadWindow ID="rwTestWindow" runat="server" Width="1000px"

Behaviors="Close, Move, Reload" KeepInScreenBounds="True" Height="450px"

Title="Test Window" OnClientClose="testalert">

How will my variable "foo" get set?   I realize I can inject javascript to set a global variable, but where in my code behind would I do that?   Let's say I have 4 Rad Windows on my page.  I need global variable foo to be different depending upon which window was closed.  I would somehow have to set variable foo when each window initializes. There has to be an easier way.  Maybe I could disable the normal close (X) button, and add my own close button..?  then I could pass  command arguments to my function at least.  Thoughts?

Thanks.





0
Pat Huesers
Top achievements
Rank 1
answered on 23 Jan 2012, 07:51 PM
Nevermind.  I got it figured out using the link to http://www.telerik.com/community/code-library/aspnet-ajax/button/passing-user-defined-parameters-to-client-side-event-handlers.aspx

In my page_load I am setting the onclientclose for each window

rwTestWindow.OnClientClose =

 

"function(args){testalert('rwCounterOffer');}"

My testalert function now displays an alert box with the passed parameter.  Thank you for the assistance!

 

Tags
Window
Asked by
D O
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Alain
Top achievements
Rank 1
Pat Huesers
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or