RadAjaxManager in external .js

9 posts, 0 answers
  1. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 13 Mar 2013 Link to this post

    Hi

    I have developed an external .js file for an ASP.NET system which executes the following...
    function ProcessUpdate(arg) {
        var ram = $telerik.$("[id$='RadAjaxManager1']").attr("id");
        var ajaxManager = $find(ram);
        if (!arg) { ram.ajaxRequest("Rebind"); } else if (arg == 'navigateToInserted') ram.ajaxRequest("RebindAndNavigate"); else if (arg.match(/navigateToDeleted.*/)) ram.ajaxRequest(arg);
    }


      I am trying to execute the RadAjaxManager ajaxRequest along with the proper argument, but so far all I am getting is an error 'Cannot call method 'ajaxRequest' of null'.  I am able to get reference to the RadAjaxManager object on the page, but the method is not available for referencing at this point.

    Any help or comments would be appreciated!

    Regards
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 18 Mar 2013 Link to this post

    Hello Neftali,

    Could you please try to access the RadAjaxManager as shown below and call the Ajax request then:
    $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("content");


    Kind regards,
    Maria Ilieva
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 18 Mar 2013 Link to this post

    Hi Maria

    Thanks for your response.  I have tried that but Thanks for your response.  I have tried that but the $find method method does load the RadAjaxManager object.  As I have read on other posts it simply
    does not work when using external .js files.  I am able to load the object with 

    $telerik.$("[id$='RadAjaxManager1']").attr("id")

    but the ajaxRequest method is not exposed!  I do see other methods such as ajaxComplete, ajaxSend, ajaxStart, etc.

    Any ideas if these could help me achieve the same as with ajaxRequest?

    Thanks again!
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Mar 2013 Link to this post

    Hi Neftali,

    I tested the same approach on my end and it works properly. You could see the online demo below which presents the same approach and which works as expected:

    http://demos.telerik.com/aspnet-ajax/ajax/examples/common/recreatescripts/defaultcs.aspx

    Test it on your end and verify what the difference in your case is.


    Kind regards,
    Maria Ilieva
    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.
  6. moegal
    moegal avatar
    273 posts
    Member since:
    Jul 2007

    Posted 21 Mar 2013 Link to this post

    you could try to set  ClientIDMode="Static" on radajaxmanager so you get the same ID that you set.

    Just a thought.

  7. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 22 Mar 2013 Link to this post

    Hi Maria

    Thanks for the reply.  I saw the example on the link you sent.  Now I am able to run without error on the ajaxrequest, but the actual server side method is not running for some reason.  I suspect that it is occurring but on the wrong instance of the RadAjaxManager.  My .js code now looks like this ...

    function ProcessUpdate(arg) {
        var ajaxPanel = $telerik.$("[id$='RadAjaxPanel1']").attr("id");
        var ram = $find(ajaxPanel);
        if (!arg) { ram.ajaxRequest("Rebind"); } else if (arg == 'navigateToInserted') ram.ajaxRequest("RebindAndNavigate"); else if (arg.match(/navigateToDeleted.*/)) ram.ajaxRequest(arg);
    }

    The server side code not executing being ...

    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
        Select Case e.Argument
            Case "Rebind"
                gvList.Rebind()
            Case "RebindAndNavigate"
                gvList.MasterTableView.CurrentPageIndex = IIf(gvList.MasterTableView.PageCount > 0, gvList.MasterTableView.PageCount - 1, 0)
                gvList.Rebind()
            Case Else
                'more steps here
        End Select

    Basically, what I am trying to achieve is to execute the 'refreshGrid' logic once a RadWindow is closed.  But instead of having the js code on each Grid page, since the logic is the same, move the code to an external .js code so all the pages would inherit the same logic. 

    For now it seems I'll have to leave it on each page.



  8. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 26 Mar 2013 Link to this post

    Hello Neftali,

    It would be best if you could move the logic in each page. When using an external JavaScript file you may experience problems obtaining a reference to the RadAjax and in some scenarios the AJAX request might not trigger.

    All the best,
    Angel Petrov
    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.
  9. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 27 Mar 2013 Link to this post

    Hello Angel

    Thanks for the reply.  I was afraid of that since that is exactly what I'm experiencing it. Even though I am able now to reference the RadAjaxManager object still the server side method won't fire!

    Cheers
  10. nfigueroa
    nfigueroa avatar
    21 posts
    Member since:
    Apr 2010

    Posted 02 May 2014 Link to this post

    For anyone interested

    I have found a solution to this problem!  After months without trying I found out I was referencing the RadAjaxPanel instead of the RadAjaxManager.  Now it works for all the pages.  Hope is useful to anyone out there!
    function ProcessUpdate(arg) {
        var ram = $telerik.$("[id$='RadAjaxManager1']").attr("id");
        if (!arg) { $find(ram).ajaxRequest("Rebind"); } else if (arg === 'navigateToInserted') { $find(ajaxPanel).ajaxRequest("RebindAndNavigate"); } }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017