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

RadAjaxManager with multiple user control ajax request handlers?

2 Answers 88 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Veteran
Jay asked on 20 Oct 2016, 02:31 PM

So, I have a page with multiple user controls. There is a RadAjaxManager on the page. Each user control needs to make ajaxRequests from javascript, and I would like each control to handle that itself. Is this possible?

So, for instance, I have control1 with the following in its code behind:

protected void Page_Load(object sender, System.EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(Control1_AjaxRequest);
}

and control2 with

protected void Page_Load(object sender, System.EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(Control2_AjaxRequest);
}

and in javascript, control1 does

$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest(dataString);

and I end up in Control2_AjaxRequest rather than Control1_AjaxRequest.

Is what I'm trying to do possible? If so, how? I'm currently trying to do this by adding a RadAjaxPanel to each control and invoking ajaxRequest on it, but I'm running into some code block issues with this that weren't there with RadAjaxManager.

2 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 25 Oct 2016, 12:08 PM
Hello Jay,

When using RadAjaxManager you should have only one control on the highest hierarchy page. Usually this would be a MasterPage. Then, you can handle the AjaxRequest event for that control and implement specific logic depending on the passed arguments.

The code snippet below outlines the approach:


protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    if (e.Argument == "control1_request")
    {
        // handle request from control 1
    }
    else if (e.Argument == "control2_request")
    {
        // handle request from control 2
    }
}



For additional information on using AjaxManager with UserControls please refer to the following articles.




Regards,
Viktor Tachev
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
Jay
Top achievements
Rank 1
Veteran
answered on 25 Oct 2016, 12:23 PM
Thanks, Viktor. That's the approach I ended up with too, I was just wondering if there was something I was overlooking.
Tags
Ajax
Asked by
Jay
Top achievements
Rank 1
Veteran
Answers by
Viktor Tachev
Telerik team
Jay
Top achievements
Rank 1
Veteran
Share this question
or