【问题标题】:Unable to call webmethod in autocomplete textbox无法在自动完成文本框中调用 webmethod
【发布时间】:2011-08-03 08:41:54
【问题描述】:

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?

【问题讨论】:

  • 它在做什么?尝试使用Fiddler 观察网络流量。
  • @John Saunders 我在本地机器上运行它。
  • @Chris:为什么会出现这个问题?
  • @John Saunders 我不知道。我可以在公共 MyService() 函数上看到“黄色”断点,但在我调用的那个,即 GetMaterialId 上看不到。有什么建议吗?
  • @Chris:我的意思是为什么你在本地机器上运行会出现问题?

标签: asp.net autocomplete ajaxcontroltoolkit webmethod


【解决方案1】:

我认为你的方法签名是错误的。它应该是:

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

其中 count 是要返回的项目数。

【讨论】:

  • 我也试过了,但是编译器根本没有用到这个功能。
【解决方案2】:

您需要像这样添加ScriptMethodAttribute

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

【讨论】:

    【解决方案3】:

    Myabe 您的项目没有设置为 AJAX.NET 站点;试试Adding ASP.NET AJAX to an Existing ASP.NET Application

    【讨论】:

      【解决方案4】:

      您需要在您的源页面中注册 Assembly="AjaxControlToolkit":

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

      【讨论】:

        猜你喜欢
        • 2016-02-20
        • 2016-10-29
        • 1970-01-01
        • 1970-01-01
        • 2012-03-18
        • 1970-01-01
        • 2011-04-18
        • 2010-09-22
        相关资源
        最近更新 更多