locked
Run Code after Web Service RRS feed

  • Question

  • User1225369314 posted

    Hi, I'm running a web service to populate cascading drop down boxes.

        Level2: <asp:DropDownList ID="ddlLevel2" runat="server" />
        <ajaxToolkit:CascadingDropDown ID="ccdLevel2" runat="server" TargetControlID="ddlLevel2" 
            ParentControlID="ddlLevel1" Category="Level2" 
            ServicePath="Helper.asmx" ServiceMethod="GetLevel2" />
        <br />

    What I am trying to do is run some code after the web service has finished populating the drop down box.

    Is this possible?

    Many Thanks

    Wednesday, April 17, 2013 12:32 PM

Answers

  • User220959680 posted

    http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services provides various alternatives to achieve the functionality.

    As suggested earlier a Callback function can be invoked after web service returns data that is shown below.

    Note that service and client should be on same domain due to CORS (Cross-Origin-Resource-Sharing). There are work arounds as discussed at https://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/

    //Calling a Web Service with a JavaScript proxy.
    
    
    function GetCustomerByCountry()
    {
         var country = $get("txtCountry").value;
       //onWSRequestComplete is callback function that is invoked  after web service returns data
        InterfaceTraining.CustomersService.GetCustomersByCountry(country, OnWSRequestComplete);
    }
    
    //callback function named OnWSRequestComplete that should be invoked when the asynchronous //Web Service call returns. OnWSRequestComplete handles the array of Customer objects returned from //the service and converts them into a table 
    function OnWSRequestComplete(results)
    {
         if (results != null)
         {
              CreateCustomersTable(results);
              GetMap(results);
         }
    }


    when the issue is still not resolved, post your source code (Service and client with configuration files) making sure that sensitive info is decoded.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 17, 2013 5:26 PM

All replies

  • User220959680 posted

    Wednesday, April 17, 2013 1:46 PM
  • User1225369314 posted

    Thanks very much for this.

    I have spent a couple of hours on it but I couldnt get any further sorry.

    What I am looking for is some code which I can put somewhere like this

    If WebService has finished Then

    //run some code

    End if

    What would this look like?

    Many thanks

    Wednesday, April 17, 2013 4:33 PM
  • User220959680 posted

    http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services provides various alternatives to achieve the functionality.

    As suggested earlier a Callback function can be invoked after web service returns data that is shown below.

    Note that service and client should be on same domain due to CORS (Cross-Origin-Resource-Sharing). There are work arounds as discussed at https://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/

    //Calling a Web Service with a JavaScript proxy.
    
    
    function GetCustomerByCountry()
    {
         var country = $get("txtCountry").value;
       //onWSRequestComplete is callback function that is invoked  after web service returns data
        InterfaceTraining.CustomersService.GetCustomersByCountry(country, OnWSRequestComplete);
    }
    
    //callback function named OnWSRequestComplete that should be invoked when the asynchronous //Web Service call returns. OnWSRequestComplete handles the array of Customer objects returned from //the service and converts them into a table 
    function OnWSRequestComplete(results)
    {
         if (results != null)
         {
              CreateCustomersTable(results);
              GetMap(results);
         }
    }


    when the issue is still not resolved, post your source code (Service and client with configuration files) making sure that sensitive info is decoded.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 17, 2013 5:26 PM