How to fire multiple js function on RadAjaxManager OnReponseEnd ?

1 Answer 26 Views
Ajax
Emmanuel
Top achievements
Rank 1
Iron
Emmanuel asked on 17 Nov 2021, 10:17 AM

Hello,

In a UserControl, in the ascx file, we have a RadAjaxManagerProxy.

In codebehind, we have this code :

RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
manager.ClientEvents.OnResponseEnd += "responseEnd" + this.ClientID + ";";

In a page, we have 2 versions of this usercontrol.

On the last responseEnd js function is fired. The first one is not.

Do you have any idea to help me ?

 

Thank you for your help.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 17 Nov 2021, 12:52 PM

Hi Emmanuel,

I have a few suspicions here:

1. Attaching a Client-Side event must not use Concatenation like it is done in the code. See my mark with yellow:

manager.ClientEvents.OnResponseEnd += "responseEnd" + this.ClientID + ";";

 

This will set the OnResponseEnd with a different Value each time the code runs.

Once it will be set to "responseEndMyUserControl;" then it will be set to "responseEndMyUserControl;responseEndMyUserControl;" and then to "responseEndMyUserControl;responseEndMyUserControl;responseEndMyUserControl;", and this goes on every time the C# code runs.

Solution

Each time this  code executes, you will need to set the same value:

manager.ClientEvents.OnResponseEnd = "responseEnd" + this.ClientID + ";";

 

2. Assigning a Client-Side event to a Telerik Control only requires the function's name. Do not use brackets " ( ) " or semi-colons " ; " at the end of the function name. The Control will then try to find a JavaScript function that has this name and it will pass two parameters to it: sender and arguments.

manager.ClientEvents.OnResponseEnd = "responseEnd" + this.ClientID; // output: "responseEndMyUserControl"

 

3. By concatenating the UserControl's Client ID in the event handler, you will need to make sure you have JavaScript Functions with that name or it will fail.

Be sure to have a proper Handler for each event. Telerik Controls pass two parameters to Client-Side events. Those are the sender and arguments

Example:

function responseEndMyUserControl(sender, args) {

}
function responseEndDifferentUserControl(sender, args) {

}

 

Be sure to correct these little errors and try again. If the issue still persists, share the implementation (ASPX, ASPX.CS) and share both the Master/Content/UserControl as they are related and affect each other.

I could only help if I see the complete implementation. That will allow me to understand what is happening, and eventually replicate the issue locally.

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Emmanuel
Top achievements
Rank 1
Iron
commented on 17 Nov 2021, 03:48 PM

Hello,

 

Thank you for your reply.

I tryied attaching client side event on radajaxmanager without concatenation but this only fires the javascript function present in the last usercontrol of the page.

In the ascx, I put this code : 

function responseEnd<%: this.ClientID %>(sender, eventArgs) {

so I do have a different js function for each userControl instance.

But only the last function is fired.

Attila Antal
Telerik team
commented on 17 Nov 2021, 04:35 PM | edited

Emmanuel,

You can create a sample project that I can run on my PC and I can check the issue for you. Although, I do not see why you could not use a single JavaScript function for all the UserControls. You have IF/ELSE statements in JavaScript as well, so you could do different things depending on the UserControl.

In any case, there could be many different scenarios this can be built up, and I can only pinpoint the issue if I see the entire project. Otherwise, I can only make guesses and suggestions.

Tags
Ajax
Asked by
Emmanuel
Top achievements
Rank 1
Iron
Answers by
Attila Antal
Telerik team
Share this question
or