ajaxRequest not working

6 posts, 0 answers
  1. Rich
    Rich avatar
    25 posts
    Member since:
    Jun 2010

    Posted 26 Oct 2010 Link to this post

    I am using your RadWindow control to pop up a dialog box containing an aspx page.  When the page is dismissed via an OK button, the logic closes the window and tries to create a postback to communicate the results to the calling form.

    The popup form opens correctly, but when the OK button is pressed the JS logic to perform the ajax request fails with the error: "Object doesn't support this property or method."  Here is the JS code:

    function

     

     

    CloseRadWindowPostback(sArgument) {

     

        ctl00_ctlAjaxManager.ajaxRequest(sArgument);   // failure occurs here

     

     

        var oWindow = GetRadWindow();

     

        oWindow.close();

    }

    Just to be clear, the value "sArgument" is set to a string, and for the sake of testing I have eliminated the jQuery find logic, and used the clientID of the ajax manager control directly in the JS code.

    The dialog form is created with a Master page containg the RadAjaxManager control, and viewing the source of the dialog form shows that the ajax manager object exits:

    <script type="text/javascript">
    //<![CDATA[
    Sys.WebForms.PageRequestManager._initialize('ctl00$ctlScriptManager', document.getElementById('aspnetForm'));
    Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00$ctlAjaxManagerSU'], [], [], 90);
    //]]>
    </script>

    <!-- 2010.2.826.35 --><div id="ctl00_ctlAjaxManagerSU">
    <span id="ctl00_ctlAjaxManager" style="display:none;"></span>

    Why is the ajaxRequest code failing?

  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 27 Oct 2010 Link to this post

    Hi Richard,

    When exactly do you execute CloseRadWindowPostback()? If you are doing this in window.onload, you need to consider the fact that all ASP.NET AJAX controls are loaded on a later stage (Sys.Application.Load) - more information on the subject can be found in various resources on the Net - for example you could check this article. Also, I would recommend to get a reference to the RadAjaxManager by using the approach described here.

    All the best,
    Georgi Tunev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rich
    Rich avatar
    25 posts
    Member since:
    Jun 2010

    Posted 27 Oct 2010 Link to this post

    Georgi,

    The CloseRadWindowPostback JS routine is called after the user has interacted with the form, and when an OK-type button in the form is pressed.  So the resources should be fully loaded, and the only reason that this routine is called and used is to pass the user-specified results from the popup dialog back to the calling form.

    This JS routine is in a JS script file that is loaded from the head tag of the Master page associated with the popup dialog.  The server side logic injects JS code into the page to call this routine after the OK button processing has been done.  Here is the server code:

     

     

    Public Shared Sub ClosePopupPagePostback(ByVal ctlClientScriptMgr As ClientScriptManager, ByVal oPage As Object, ByVal sArgument As String)

     

     

     

        Dim sScript As String = "<script>CloseRadWindowPostback(""%argument%"")</script>".Replace("%argument%", sArgument)

     

        ctlClientScriptMgr.RegisterStartupScript(oPage.GetType(),

     

    "CloseRadWindowPostback", sScript)

     

     

     

    End Sub

     


    This works properly because the CloseRadWindowPostback routine is called and then fails when trying to do the ajaxRequest call.

    I should note that both the popup dialog and the calling form have instances of both the AjaxManager and the ScriptManager defined on their Master pages (NOT in the forms themselves).  The popup form is created server-side via an Add Window call to a WindowManager control defined on the calling form (NOT in its Master page), as follows:

    . . . (create popup logic code - this works properly)

    ctlWindowManager.Windows.Add(oWindow)


    The reference that you sent doesn't seem to make sense in this case because the AjaxManager on the popup dialog is only being used to handle the ajaxRequest call, which is not related to any control on the popup form.

    I am totally open to other methods of accomplishing the same thing.  If there is another way to achieve the same effect (to fire an event on the calling page with the results of the popup dialog), then let me know.

    Rich Sorensen
  5. Rich
    Rich avatar
    25 posts
    Member since:
    Jun 2010

    Posted 27 Oct 2010 Link to this post

    Georgi,

    I did some more testing with this and get the same JS error ("Object doesn't support this property or method") regardless of how I reference the AjaxManger control - either as ctlAjaxManager.ClientID or RadAjaxManager.GetCurrent(Page).ClientID

    If I put a stop in the CloseRadWindowPostback routine on the line:

    oManager.ajaxRequest(sArgument);


    I can confirm that the variable "oManager" refers to the control Telerik.Web.UI.RadAjaxManager.

    I also tried it both with and without "sArgument", so this seems to be a hard error.

    Rich Sorensen
  6. Rich
    Rich avatar
    25 posts
    Member since:
    Jun 2010

    Posted 28 Oct 2010 Link to this post

    Georgi,

    Last night I tried another method to skin this cat - implementing the ICallbackEventHandler interface for sending a callback to the parent page from the popup page.  Note that in my case both the parent and the popup forms have Master pages.

    But that method didn't work either, as the crux of the problem was a reliable way to get a reference from the popup window back to the parent so that the parent form can be "woken up" by calling a JS routine in the parent.

    Using "window.opener" doesn't work because the popup window was not opened by the parent.  If the ajaxRequest functionality also can't be used to wake up the parent form, how can this be done?

    Rich Sorensen
  7. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 02 Nov 2010 Link to this post

    Hello Richard,

    As Georgi said, you try to use an AJAX object in a very early stage of the AJAX controls client-side objects' live cycle. In your case you need to use the Sys.Application.Load event in order to get reference the RadAjaxManager control:
    function CloseRadWindowPostback(sArgument)
    {
        function f()
        {
            Sys.Application.remove_load(f);
            var oManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
            ctl00_ctlAjaxManager.ajaxRequest(sArgument);   // tThis will work
     
            // ...
        }
     
        Sys.Application.add_load(f);
    }

    When you click the button a postback occurs and the client-side objects are destroyed. When the page comes back from the server the client-objects are recreated again. This is why you need to wait for the Sys.Application.Load event in order to reference the AJAX controls.


    Regards,
    Fiko
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017