How can I set the select url client side?

4 posts, 0 answers
  1. moegal
    moegal avatar
    273 posts
    Member since:
    Jul 2007

    Posted 05 Jul 2015 Link to this post

    I am doing the following at the moment and it seems to work, not sure there is not a method I could use.

     
    var dataSource;
            function RequestStart(sender, args) {
                dataSource = $find('<%= RadClientDataSource1.ClientID %>');
                dataSource._transport.read.url = dataSource._transport.baseUrl + "GetListProducts/3";
            };

     Thanks, Marty

     

  2. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 08 Jul 2015 Link to this post

    Hello,

    Yes, this approach seems okay. You could use get_transport() which will also return _transport property of the ClientDataSource.
    The client-side API does not expose separate methods for configuration of the URL because this is generally expected to be a static setting when you are making a request to a web service.  And additional options can be passed as parameters to the web service call in the HTTP request.
    If you are using Web API to retrieve data the approach for dynamic changes of the request URL in the ClientDataSource is indeed more appropriate in this case.

    Regards,
    Marin
    Telerik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. moegal
    moegal avatar
    273 posts
    Member since:
    Jul 2007

    Posted 09 Jul 2015 in reply to Marin Link to this post

    Marin,

     Thanks.  So how do I pass additional parameters to the web service in the HTTP request?

     Marty

  5. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 13 Jul 2015 Link to this post

    Hello,

    Sample code of this approach is shown in this online demo:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx
    You can handle the OnCustomParameter event of the ClientDataSource and pass the parameters there:
    function ParameterMap(sender, args) {
                 
                if (args.get_type() == "read / create / update... etc" && args.get_data()) {
                    args.set_parameterFormat({ parameterName: parameterValue });
                }
            }

    This way the ClientDataSource will make a request and send the parameters you specified in the event. Of course on the server side the service method should also expect such parameter.
    public void ServiceMethod(string parameterName)
        {
            //....
        }


    I hope this helps. Let me know if you have any other questions.

    Regards,
    Marin
    Telerik
Back to Top