开发者

Unable to call webmethod in autocomplete textbox

开发者 https://www.devze.com 2023-02-23 13:09 出处:网络
aspx page code: <ajax:ScriptManager ID=\"ScriptManager1\"runat=\"server\"> <Services > <ajax:ServiceReference Path=\"MyServic开发者_运维百科e.asmx\" />

aspx page code:

<ajax:ScriptManager ID="ScriptManager1"  runat="server">
 <Services >
  <ajax:ServiceReference Path="MyServic开发者_运维百科e.asmx" />
 </Services>
</ajax:ScriptManager>

 <asp:TextBox ID="txtMaterialNo"  
             Width="100%" runat="server" ></asp:TextBox>


       <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" CompletionInterval="20"
        MinimumPrefixLength="1" ServiceMethod="GetMaterialId"
         ServicePath="MyService.asmx" TargetControlID="txtMaterialNo"> </cc1:AutoCompleteExtender>

MyService.asmx

    [ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class MyService : System.Web.Services.WebService
 public MyService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [System.Web.Services.WebMethod]
    public string[] GetMaterialId(string prefixMaterial)
    {
...... code
.... return
    }
  }

But when I am typing into the textbox no suggestion are coming, when I am placing the breakpoint at GetMaterialId I can see that it is not coming to this function but it is calling MyService on textchange.

How to fix this? Why it is calling the constructor but not the webmethod?


Myabe your project is not setup as an AJAX.NET site; try Adding ASP.NET AJAX to an Existing ASP.NET Application


You need to add the ScriptMethodAttribute like so:

    [WebMethod]
    [ScriptMethod]
    public string[] GetMaterialId(string prefixMaterial)
    {
        ...... code
        .... return
    }


Your method signature is wrong, I think. Its supposed to be:

List<string> GetMaterialId(string prefixMaterial, int count)

where count is the number of items to return.


You need to Register Assembly="AjaxControlToolkit" in your source page:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
0

精彩评论

暂无评论...
验证码 换一张
取 消