0

我的 asp.net 页面上有一个简单的文本框,其中包含一个更新面板:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" ChildrenAsTriggers="true" runat="server">
                                    <ContentTemplate>
                                        <asp:TextBox ID="txtShipToName" runat="server" 
                                            ToolTip="Enter a name such as a company name or contact name." 
                                            MaxLength="50"></asp:TextBox>
                                    </ContentTemplate>
                                    </asp:UpdatePanel>

试图实现自动完成......所以我创建了一个 .ashx 文件(一个 IHttpHandler),如下所示:

 public class LoadAddress : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            DataSet ds;
            Dictionary<long, string> lstAddresses = new Dictionary<long, string>();

            ds = BL.GetAddresses(string.Empty, "both", 0, 100); //just snatching some data...

            foreach(DataRow dr in ds.Tables[0].Rows)
            {
                lstAddresses.Add(Convert.ToInt64(dr["AddressID"].ToString()), dr["Name"].ToString());
            }

            StringBuilder builder = new StringBuilder();

            foreach (KeyValuePair<long, string> item in lstAddresses)
            {
                builder.Append(string.Format("{0}|{1}|{2}",
                      item.Value,
                      item.Key,
                      Environment.NewLine));
            }

            context.Response.Write(builder.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

但我不确定如何在 jquery 中调用它,我试过:

 $("#<%= txtShipToName.ClientID %>").autocomplete('LoadAddress.ashx').
        result(function (event, data, formatted) { // data[0] : Address, data[1] : Address ID
        });

但是结果是未定义的,请注意这个方法甚至不存在......我怎样才能调用 LoadAddress.ashx?

编辑

我添加到网络配置文件中:

    <httpHandlers>
      <add verb="*" path="LoadAddress.ashx" type="MyShipper.LoadAddress"/>
    </httpHandlers>

但是自动完成似乎不起作用......在jquery中我将其更改为:

$("#<%= txtShipToName.ClientID %>").autocomplete('LoadAddress.ashx');

但就像我说的那样,不会出现自动完成功能。chrome的开发者工具没有错误。我会错过什么?

4

1 回答 1

1

您是否LoadAddress在 web.config 中注册了您的处理程序?

(iis 6):

<system.web>
  <httpHandlers>
      <add verb="*" path="LoadAddress.ashx" type="NameOfClass, NameOfAssembly"/>
  </httpHandlers>
</system.web>

(对于 iis 7+):

<system.webServer>
  <handlers>
      <add name="LoadAddress" verb="*" path="LoadAddress.ashx" type="NameOfClass, NameOfAssembly"/>
  </handlers>
</system.webServer>
于 2012-05-01T14:19:36.760 回答