Wednesday, June 26, 2013

Webservice is Undefined Error (ASP.NET 4.0)

1. First step is to add reference to the web service using Ajax Script Manager:
 <asp:ScriptManager ID="ajaxManager" runat="server">  
     <Services>  
       <asp:ServiceReference Path="~/Services/ProductService.asmx" />  
     </Services>  
   </asp:ScriptManager>  
2. Secondly is to include the namespace in calling the webservice method
From
  ProductService.GetProducts(  
            function (data) {  
              $.each(data, function (index, elem) {  
                $("<option />")  
                 .text(elem.ProductName)  
                 .val(elem.ProductID)  
                 .appendTo("#products");  
              });  
            }  
       );  
To
  AccessingServerSideDataUsingClientScript.Services.ProductService.GetProducts(  
            function (data) {  
              $.each(data, function (index, elem) {  
                $("<option />")  
                 .text(elem.ProductName)  
                 .val(elem.ProductID)  
                 .appendTo("#products");  
              });  
            }  
       );  

Reference: http://omensblog.blogspot.com/2007/07/aspnet-ajax-web-service-calls-from.html
Greg

0 comments:

Post a Comment