aspx页面代码:
<ajax:ScriptManager ID="ScriptManager1" runat="server">
<Services >
<ajax:ServiceReference Path="MyService.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
}
}
但是当我在文本框中输入时,没有提示,当我将断点放在GetMaterialId时,我可以看到它没有出现在这个函数中,但它在textchange上调用了MyService。
如何解决这个问题?为什么它只调用构造函数而不调用webmethod?
发布于 2011-04-11 21:22:21
您需要添加ScriptMethodAttribute,如下所示:
[WebMethod]
[ScriptMethod]
public string[] GetMaterialId(string prefixMaterial)
{
...... code
.... return
}
发布于 2011-04-16 23:30:43
可能您的项目未设置为AJAX.NET站点;请尝试Adding ASP.NET AJAX to an Existing ASP.NET Application
发布于 2011-04-11 21:05:47
我想你的方法签名是错误的。它应该是:
List<string> GetMaterialId(string prefixMaterial, int count)
其中count是要返回的项数。
https://stackoverflow.com/questions/5626766
复制相似问题