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

ResponseScripts.Add can not work

6 Answers 212 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 29 Aug 2012, 06:53 AM
Hi,guys,

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

Sort by
0
Maria Ilieva
Telerik team
answered on 03 Sep 2012, 01:47 PM
Hello Jack,

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
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
Sivajith
Top achievements
Rank 1
answered on 19 Dec 2013, 05:05 PM
hi,

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');");

0
Sivajith
Top achievements
Rank 1
answered on 19 Dec 2013, 05:29 PM
hi, 

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"");");
0
Sachita
Top achievements
Rank 1
Iron
Iron
Iron
answered on 24 Mar 2021, 04:53 AM

<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?

0
Rumen
Telerik team
answered on 26 Mar 2021, 10:02 AM

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.

0
Sachita
Top achievements
Rank 1
Iron
Iron
Iron
answered on 13 May 2021, 09:47 AM | edited on 13 May 2021, 10:45 AM

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?

 

Rumen
Telerik team
commented on 13 May 2021, 10:02 AM | edited

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 


Rumen
Telerik team
commented on 13 May 2021, 10:49 AM

Comment on your update: Yes, EnableAjax is supporting the modern browsers - of course, it is recommended to use some of the recent versions of the Telerik.Web.UI.dll (see here).

"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.
Tags
General Discussions
Asked by
Jack
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Sivajith
Top achievements
Rank 1
Sachita
Top achievements
Rank 1
Iron
Iron
Iron
Rumen
Telerik team
Share this question
or