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

RadAjaxManager in external .js

9 Answers 151 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
nfigueroa
Top achievements
Rank 1
nfigueroa asked on 13 Mar 2013, 08:16 PM
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

9 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 18 Mar 2013, 11:28 AM
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.
0
nfigueroa
Top achievements
Rank 1
answered on 18 Mar 2013, 02:29 PM
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!
0
Maria Ilieva
Telerik team
answered on 21 Mar 2013, 07:18 PM
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.
0
moegal
Top achievements
Rank 1
answered on 21 Mar 2013, 09:03 PM
you could try to set  ClientIDMode="Static" on radajaxmanager so you get the same ID that you set.

Just a thought.

0
nfigueroa
Top achievements
Rank 1
answered on 22 Mar 2013, 05:38 PM

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.



0
Angel Petrov
Telerik team
answered on 26 Mar 2013, 04:51 PM
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.
0
nfigueroa
Top achievements
Rank 1
answered on 27 Mar 2013, 02:46 PM
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
0
nfigueroa
Top achievements
Rank 1
answered on 02 May 2014, 07:14 PM
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"); } }
0
Maria Ilieva
Telerik team
answered on 07 May 2014, 01:10 PM
Hello Neftali,

Thank you for sharing your solution which  will be of a big hep for other users that are facing the same issue.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
nfigueroa
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
nfigueroa
Top achievements
Rank 1
moegal
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or