OnClientClose Postback Fires On Page Load

8 posts, 0 answers
  1. D O
    D O avatar
    9 posts
    Member since:
    Jul 2009

    Posted 23 Sep 2009 Link to this post

    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>

     

  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 24 Sep 2009 Link to this post

    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.
  3. Alain
    Alain avatar
    1 posts
    Member since:
    Jan 2011

    Posted 09 May 2011 Link to this post

    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.
  4. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 12 May 2011 Link to this post

    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.

  5. Pat Huesers
    Pat Huesers avatar
    18 posts
    Member since:
    Jan 2008

    Posted 20 Jan 2012 Link to this post

    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.



  6. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4529 posts

    Posted 23 Jan 2012 Link to this post

    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
  7. Pat Huesers
    Pat Huesers avatar
    18 posts
    Member since:
    Jan 2008

    Posted 23 Jan 2012 Link to this post

    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.





  8. Pat Huesers
    Pat Huesers avatar
    18 posts
    Member since:
    Jan 2008

    Posted 23 Jan 2012 Link to this post

    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!

     

Back to Top