New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Sending Additional Information to the Web Service
This article shows how you can easily send additional information from the client to the web service. You can use the OnClientRequestStart event to set attributes of the context object that is passed to the web service with each request. The context object is an object of type IDictionary.
First you have to use the OnClientRequestStart client event to set some custom attributes on the context:
ASPNET
<telerik:RadGantt RenderMode="Lightweight" runat="server" ID="RadGantt1"
OnClientRequestStart="onClientRequestStart">
<WebServiceSettings Path="GanttService.asmx" />
</telerik:RadGantt>
JavaScript
function onClientRequestStart(sender, eventArgs) {
args.get_context().ProjectName = "Products";
}
After that you have to change the corresponding Web Service methods to take the context as an additional parameter:
C#
/// <summary>
/// Summary description for GanttService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class GanttService : System.Web.Services.WebService
{
private WebServiceController _controller;
public WebServiceController Controller
{
get
{
if (_controller == null)
{
_controller = new WebServiceController(new XmlGanttProvider(Server.MapPath("Tasks.xml"), true));
}
return _controller;
}
}
[WebMethod]
public IEnumerable<TaskData> GetTasks(IDictionary<string, object> context)
{
return Controller.GetTasks().ToList();
}
[WebMethod]
public IEnumerable<TaskData> InsertTasks(IEnumerable<TaskData> models, IDictionary<string, object> context)
{
return Controller.InsertTasks(models);
}
[WebMethod]
public IEnumerable<TaskData> UpdateTasks(IEnumerable<TaskData> models, IDictionary<string, object> context)
{
return Controller.UpdateTasks(models);
}
[WebMethod]
public IEnumerable<TaskData> DeleteTasks(IEnumerable<TaskData> models, IDictionary<string, object> context)
{
return Controller.DeleteTasks(models);
}
[WebMethod]
public IEnumerable<DependencyData> GetDependencies(IDictionary<string, object> context)
{
return Controller.GetDependencies();
}
[WebMethod]
public IEnumerable<DependencyData> InsertDependencies(IEnumerable<DependencyData> models, IDictionary<string, object> context)
{
return Controller.InsertDependencies(models);
}
[WebMethod]
public IEnumerable<DependencyData> DeleteDependencies(IEnumerable<DependencyData> models, IDictionary<string, object> context)
{
return Controller.DeleteDependencies(models);
}
}
And finally you can extract the custom attributes from the context:
C#
[WebMethod]
public IEnumerable<TaskData> GetTasks(IDictionary<string, object> context)
{
var projectName = context["ProjectName"].ToString();
var tasks = Controller.GetTasks().ToList();
// filter tasks based on project name
return tasks;
}