RadWindow callback function executes before the window

5 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 21 May 2013 Link to this post

    I'm trying to show an alert before a page redirect (after a form submission).
    I tryed every possible scenario but it seems that the callback function (wich actually performs the redirect) is always executed before the window.

    As a last option I tryed
    <asp:Panel ID="AjaxPanel" runat="server" defaultbutton="LoginConfirm">
        <telerik:RadScriptBlock ID="RadScriptBlock" runat="server">
            <script type="text/javascript">
                activeAjaxRequest = false;
                noPermanentLogin('sdf');
            </script>
        </telerik:RadScriptBlock>
    where noPermanentLogin just:
    function noPermanentLogin(args) {
        radalert('Radalert is called from the client!', 330, 180, 'Client RadAlert', alertCallBackFn(args), '');
    }
    function alertCallBackFn(args) {
        alert(args);
        //window.location.href = args
    }

    Now when I first load the page the RadWindow should open each time and upon clicking "OK" button the alert should fire.
    Instead the alert fires and the window is not created because of:
    Uncaught TypeError: Cannot call method 'radalert' of undefined
    It seems that the radwindow object has not yet been instantiated but nonetheless the callbackfunction executes the same.. this is quite mindblowing to me...

    In the real scenario I tryed several versions, whose behaviour (in all situations) is that the callbackfunction gets executed BEFORE the window is showed. In those cases btw the window is showed.
    So I tryed in code behind:
    Me.AjaxManager.ResponseScripts.Add("noPermanentLogin('returnUrl')")
    Then I tryed
    RadWindowManager.RadAlert("Testina", Nothing, Nothing, "Totolo", "window.location.href = '" & returnUrl & "'")
    And finally I tryed:
    RadWindowManager.RadAlert("Testina", Nothing, Nothing, "Totolo", "redirectFunction('testurl')")
    (in this last case redirectFunction calls the window redirect and is in an external JS in the page).

    Why the callback function is executed even before showing the radalert?
    Thanks in advance for your help




  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 23 May 2013 Link to this post

    Hello Massimiliano,

    The callback function of the RadAlert is a function object, i.e. you need to pass its name. This is explained and shown in the following places:
    http://www.telerik.com/help/aspnet-ajax/window-dialogs-alert.html
    http://demos.telerik.com/aspnet-ajax/window/examples/browserdialogboxes/defaultcs.aspx

    Adding the parentheses causes the function to execute immediately as this is their purpose.

    What you need is:
    radalert('Radalert is called from the client!', 330, 180, 'Client RadAlert', alertCallBackFn, '');

    The error that you get is because the script is called from the code-behind and it is executed too early, you need to use the Sys.Application.Load event, as shown here and here, or you can simply use the server-side RadAlert() method you can see in the above demo.


    Regards,
    Marin Bratanov
    Telerik
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 23 May 2013 Link to this post

    Thank you Marin tomorrow I'll check your suggestions. I think I got the parenthesis stuff... the "args" inside it is the action executed on the alert windows so I cannot pass "args" to the function in the radalert call otherwise is like I'm providing the action already.
    I should find another way to pass back the url variable then during ajax, maybe a global js variable or such.

    Thanks again you  are precious as always.
  5. Travis Cotton
    Travis Cotton avatar
    10 posts
    Member since:
    Sep 2009

    Posted 28 Mar 2014 in reply to Massimiliano Link to this post

    This is a pretty old post but for anyone else who has this same issue the solution I found is this:

    In the page load method register the script you want to execute and at that time set the URL you want the system to redirect to when the alert is closed:

            Page.ClientScript.RegisterStartupScript(Me.GetType, "callBackFunction", "<script> function callBackFunction(arg) { window.location.href ='/someurl.aspx' } </script>")

    Now you can call the RadAlert like it was intended:

                        RadWindowManager1.RadAlert("<h1>Your Alert Heading</h1><p>Some message here</p>", 500, 500, "Notification", "callBackFunction")

    Works like a charm!




  6. Enrico Ariel
    Enrico Ariel avatar
    1 posts
    Member since:
    Nov 2015

    Posted 03 May Link to this post

    this is how I solved the same issue:

    On server side:

    string newId = "myParameter";
    string callBackFunction = String.Format("function(){{onSaveNewClientCallBackFunction('{0}');}}", newId);
    RadWindowManager1.RadAlert("New Item Added Successfully", 250, 250, "Message",
    callBackFunction);

    and on client side:

    function onSaveNewClientCallBackFunction(id) {
       alert(id);
    }

    I hope it can be useful.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017