Articles in this section
Category / Section

How to send custom headers to server using DataManager in .NET WebForms ?

2 mins read

You can pass any values in the Headers of ejDataManager and retrieve them at the server-side using the Request object of the HttpRequestMessage. This can be added to the headers either in the initial load of ejGrid or while performing any server-side operations like editing/adding and retrieve them at the server-side as follows.

    <div id="Grid"></div>


        dataSource: ej.DataManager({ url: "/Home/DataSource", adaptor: new ej.UrlAdaptor() }),
        allowScrolling: true,
        allowFiltering: true,
        allowPaging: true,
        load: "load",
        columns: [
                { field: "OrderID" },
                { field: "ShipCountry" },
                { field: "CustomerID" },
                { field: "EmployeeID" },
                { field: "ShipCity" }


At the load event of Grid, we have to add some values to the headers of DataManager instances.


        .Columns(col =>
            .ClientSideEvents(events => events.Load("load"))



        public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
            IEnumerable Data = new NorthwindDataContext().OrdersViews.ToList();
            var Field = Request.Headers.GetValues("field").ToList()[0];
            var Valid = Request.Headers.GetValues("IsValid").ToList()[0];
            DataResult result = new DataResult();
            DataOperations operation = new DataOperations();
            result.count = Data.AsQueryable().Count();
            if (dm.Skip != null)
                Data = operation.PerformSkip(Data, dm.Skip);
            if(dm.Take != null)
                Data = operation.PerformTake(Data, dm.Take);
            result.result = Data;
            return Json(result, JsonRequestBehavior.AllowGet);



    <ej:Grid id="Grid" runat="server" AllowPaging="true">
        <DataManager URL="Default.aspx/Data" Adaptor="WebMethodAdaptor" />
                <ej:Column Field="OrderID" />
                <ej:Column Field="ShipCountry" />
                <ej:Column Field="CustomerID" />
                <ej:Column Field="EmployeeID" />
                <ej:Column Field="ShipCity" />
        <ClientSideEvents Load="load" />      




In static methods, we cannot get the HttpRequest instance, so we have used the HttpContext.


        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static object Data(Syncfusion.JavaScript.DataManager value)
            var Field = HttpContext.Current.Request.Headers.GetValues("field").ToList()[0];
            var Valid = HttpContext.Current.Request.Headers.GetValues("IsValid").ToList()[0];
            IEnumerable Data = OrderRepository.GetAllRecords();
            int count = Data.AsQueryable().Count();
            DataOperations operation = new DataOperations();
            Data = operation.Execute(Data, value);
            return new { result = Data, count = count };


    function load(args) {
        //At the initial load of Grid, header is undefined
        this.model.dataSource.dataSource.headers = [];//So define them as array
        this.model.dataSource.dataSource.headers.push({ "field": "OrderID"});//pushing Some JSON Object
        this.model.dataSource.dataSource.headers.push({ "IsValid": true });//pushing Some JSON Object

Below screenshot shows the header values in the post request.

Figure 1: Header values in Post Request



Figure 2: Grid


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment