In one of my page,I use "RadAjaxManager.GetCurrent(Page).ResponseScripts.Add" to add some script.
What makes me amazing,the script can not work at all.
the client script:
function moveToTargetAnchor(anchorName) {
var anchor = $('a[name="' + anchorName + '"]');
if (anchor.length > 0) {
anchor[0].scrollIntoView(true);
}
var editor = $find("<%=editConent.ClientID%>");
if (editor != null) {
var anchorElement = editor.get_document().getElementsByName(anchorName);
if (anchor != null) {
anchorElement[0].scrollIntoView(true);
}
}
//alert('123');
}
the server:
RadAjaxManager.GetCurrent(Page).ResponseScripts.Add("moveToTargetAnchor(""" & item.Title & """);")
The code complete a function of going to spesific anchor.
I have a test:
when i add a "alert('123')" to the end of script,the page could go to right anchor at first;
but after displaying '123',the page looks like being refreshed.
How could this happen,anyone can help me?
Best regards,
Jack.
6 Answers, 1 is accepted
Please try to use the ScriptManager.RegisterStartupScript method as described in the topic below and verify if this makes any difference:
http://www.telerik.com/help/aspnet-ajax/ajax-execute-custom-javascript.html
All the best,
Maria Ilieva
the Telerik team
i am facing an issue regarding calling notification plugin ' Noty ' functions and also the funtion in jquery.
for example if i write function myfun()
{ alert("hai");
}
and call from code behind , it works perfectly for the code
RadAjaxManager1.ResponseScripts.Add(@"myfun();");
So what should i do to execute a script like
function noty_error(type_,text_) {
var n = noty({
text: text_,
type: type_,
dismissQueue: true,
layout: 'topCenter',
theme: 'defaultTheme',
timeout:2000
});
}
using the code
RadAjaxManager1.ResponseScripts.Add(@"noty_error('warning','Not entered anything');");
its some thing related to format issue.
it will be working fine if we write it as
RadAjaxManager1.ResponseScripts.Add(@"noty_error(""success"",""Operation completed successfully"");");
<INPUT onclick="javascript:setTimeout('window['Control_RadAjaxManager'].AsyncRequest(\'Control$ShareRadioButton\',\'\')', 0)"
Code Snippet:
private void AddAjaxResponseScripts()
{
this.RadAjaxManager.ResponseScripts.Add("Sample.Controls.init(); if(Sample.QueryAddEdit) { Sample.AddEdit.init(); } ");
}
Here Escape characters are not getting loaded properly .Missing Escape characters window['Control_RadAjaxManager'].
Current Version of Telerik 2015.3.1111.35 with .NetFramework 4.8.
Can anyone please help on this issue?
Hi Kumar,
You can try to escape the single quotes like this javascript:setTimeout('window[\'Control_RadAjaxManager\']
Note that the proper way to get reference to the RadAjax control is via the MS AJAX method: $find
$find("<%= RadAjaxManager1.ClientID %>");
as explained in this article https://docs.telerik.com/devtools/aspnet-ajax/controls/ajaxmanager/client-side-programming/overview#ajaxrequest-event.
The other ways of obtaining a reference are discussed at Get Client-side Reference to a Control Object.
Regards,
Rumen
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Rumen,
Thanks for the response.
I have tried the above $Find but still issue exists.
we have recently upgraded to .Netframework 4.8.This issue we found.
Code for first ascx page :
<ra:RadAjaxManager ID="RadAjaxManager" runat="Server"
EnableAJAX="True"
EnableOutsideScripts="True"
EnablePageHeadUpdate="True">
<AjaxSettings>
After upgrade to .Netframework 4.8 , EnableAjax="True" is not working in my usercontrol page, but works fine with .Net3.5
If I change from EnableAjax="True" to EnableAjax="False" ,Functionality is working fine with .Net4.8
so can you suggest me why this is happening? does it have any dependencies?
will enableajax property support modern browsers?
Hi Kumar,
The EnableAJAX implementation is identical for both .NET 3.5 and 4.8 and I am personally not aware of such a problem. Basically, when you set the EnableAJAX property to true (the default), all requests (controls either within the RadAjaxPanel Template or managed by the RadAjaxManager) are handled via AJAX. If this property is false, requests are handled in the legacy postback manner.
If Ajax is disabled then you can simply use the standard approach of registering client scripts on the page:
- https://stackoverflow.com/questions/320999/execute-javascript-function-after-asp-net-postback-without-ajax - https://stackoverflow.com/questions/17325974/run-javascript-function-after-postback-in-asp-net
- https://forums.asp.net/t/1904848.aspx?After+post+back+call+javascript+function
"If I change from EnableAjax="False" to EnableAjax="True" ,issue is resolved in one page." - You may want to compare both pages and find the differences which cause the problem in your app.