Unable to call webmethod in autocomplete textbox
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" %>
精彩评论