New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

OnCustomParameter Event

CustomParameter event allows you to convert the request parameters to a format suitable for the remote service. By default the data source sends the parameters using jQuery's conventions. The event is commonly used to pass additional parameters to the server. It is important to note that the names of the custom parameters should match the method's arguments names.

The event is fired after the request started but before the data is requested. This way you can set custom parameters that will be sent to the server. The following table lists all the public methods of the event.

MethodDescription
get_dataThe model which will be sent to the remote service. The value specified in the data field of the transport settings (create, read, update or destroy) is included as well.
get_typeThe type of the request which the data source makes. The supported values are "create", "read", "update" and "destroy".
get_parameterFormatGet the custom parameters that will be sent to the server.
set_parameterFormatSet the custom parameters that will be sent to the server.

The following example demonstrates how to use CustomParameter client event and pass parameter to a WebMethod.

ASP.NET
<form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        function ParameterMap(sender, args) {
            args.set_parameterFormat("{ 'productName': 'Filo Mix' }");
        }

    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" ClientDataSourceID="RadClientDataSource1" AutoGenerateColumns="false" PageSize="4">
        <MasterTableView CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product Name"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Unit Price"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="UnitsInStock" HeaderText="Units In Stock"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    <telerik:RadClientDataSource ID="RadClientDataSource1" runat="server">
        <ClientEvents OnCustomParameter="ParameterMap" />
        <DataSource>
            <WebServiceDataSourceSettings BaseUrl="WebPageTest.aspx/">
                <Select Url="GetData" RequestType="Post" DataType="JSON" ContentType="application/json; charset=utf-8" />
            </WebServiceDataSourceSettings>
        </DataSource>
        <Schema>
            <Model ID="ProductID">
                <telerik:ClientDataSourceModelField FieldName="ProductID" DataType="Number" />
                <telerik:ClientDataSourceModelField FieldName="ProductName" DataType="String" />
                <telerik:ClientDataSourceModelField FieldName="UnitPrice" DataType="Number" />
                <telerik:ClientDataSourceModelField FieldName="UnitsInStock" DataType="Number" />
            </Model>
        </Schema>
    </telerik:RadClientDataSource>
</form>

See Also

In this article
See Also
Not finding the help you need?
Contact Support