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
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
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!
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
Just a thought.
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.
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
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
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"
); } }
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.