1

我已经浏览了谷歌给我的所有答案,但它对我的问题没有帮助,抱歉。(如果我写标题,Stackoverflow也会给我)......它在里面<asp:Table>

<asp:TableCell>
    <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="UP3">
        <ContentTemplate>
            <asp:DropDownList runat="server" ID="SupplierDDL" Visible="false">
            </asp:DropDownList>
            <asp:TextBox runat="server" AutoPostBack="true" ID="tbSupplier">             
            </asp:TextBox>
            <cc1:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1" TargetControlID="tbSupplier" BehaviorID="skldjfa"
             MinimumPrefixLength="2" EnableCaching="true" ServiceMethod="SelectAllManufacturer">
            </cc1:AutoCompleteExtender>
            <asp:HiddenField runat="server" ID="hfSupplier" /
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:TableCell>

围绕这<asp:Table>也是一个更新面板。

我的服务方法应该没问题:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] SelectAllManufacturer(string prefixText, int count)
{
    ArrayList filteredList = new ArrayList();
    OracleConnection oracon = GlobalFunctions.DatabaseConnection();
    OracleDataReader oradr;
    oracon.Open();
    OracleCommand oracom = new OracleCommand(Classes.SQL.SQL4global.selectSupplierBySearchString(prefixText.ToLower()), oracon);
    oradr = oracom.ExecuteReader();
    if (oradr.HasRows == true)
    {
        while (oradr.Read())
        {
                filteredList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(
                    Convert.ToString(oradr["companyname"]) + " ** " +
                Convert.ToString(oradr["street"]) + " * " + Convert.ToString(oradr["postalcode"]) + " * " + Convert.ToString(oradr["city"]) + " * " + Convert.ToString(oradr["land"]),
                Convert.ToString(oradr["ID_Supplier"])));
        }
    }
    oradr.Close();
    oracon.Close();
    return (string[])filteredList.ToArray(typeof(string));

}

它没有给我任何错误,只是没有激活 ServiceMethode。

4

3 回答 3

2

问题只是在方法的声明中:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] SelectAllManufacturer(string prefixText, int count)

我把它改成了静态方法

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] SelectAllManufacturer(string prefixText, int count)

它奏效了。

于 2014-10-17T07:56:02.447 回答
0

问题之一可能是您没有启用 ScriptManager (ToolkitScriptManager) 控件的 PageMethods 功能。

因此,请确保您的主页面或 aspx 页面中有与此类似的代码:

<cc1:ToolkitScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true"
                        EnablePageMethods="true">
于 2013-10-31T21:02:22.010 回答
0

对我来说,答案在 Web 服务代码中更高。除了在方法上方添加[System.Web.Script.Services.ScriptMethod]外,还有一行必须取消注释。改变:

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
//  [System.Web.Script.Services.ScriptService]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
于 2014-05-28T00:27:44.953 回答