Ajax 工具包 AutoCompleteExtender

发布于 2024-12-10 07:22:33 字数 271 浏览 0 评论 0原文

我想知道是否有一种方法使用 ajax 工具包 autocompleteextender 来挂钩多个文本框控件。

原因是我们有多个文本框控件,我不喜欢使用 8 个自动完成扩展器来执行相同的操作,因为所有 8 个都需要正确初始化等等,感觉更易于维护。

编辑:

我构建了一个方法来初始化 autocompleteextender 对象并将每个对象传递给该方法,因此我唯一需要为每个对象单独设置的是 ID 和 TargetElementID。至少总比没有好,但我仍然希望有更好的解决方案。

I'm wondering if there is a way using the ajax toolkit autocompleteextender to hook into multiple textbox controls.

The reason is we have multiple textbox controls and I don't fancy using 8 autocompleteextenders to perform the same thing, as all 8 of them would need to be initialized properly and so on, one feels more maintainable.

Edit:

I constructed a method that initializes the autocompleteextender object and pass each object to that method, so the only thing I need to set seperate on each one is the ID and the TargetElementID. At least better than nothing, but I would still appreciate a better solution to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有影子陪我不离不弃 2024-12-17 07:22:33

不是特定于该问题的答案,但我一直使用 Ajax Control 工具包自动完成扩展器,但后来我发现了 Jquery 扩展器,在我看来它要好得多,而且我认为您可以轻松地做您想做的事情,尽管您需要将其分配给 jQuery 中的每个控件,但您只需要 2 个函数,一个用于获取数据,一个用于处理结果。

您执行类似于以下的操作:

  $(document).ready(function () {

    $('#<%=txtSearchBox.ClientID%>').autocomplete('/Search.ashx');
    $('#<%=txtSearchBox.ClientID%>').result(function (event, data, formatted) {
        if (data) {

            // Extract the data values
            var name = data[0]; // appears in textbox
            var dataval1= data[1];
            var dataval2= data[2];


            $("#<%=hdndataval1.ClientID%>").val(dataval1);
            $("#<%=hdndataval2 .ClientID%>").val(dataval2);
        }
    });

});

您确实必须使用隐藏字段来存储 id,但它可以使用处理程序很好地自动完成。

    public void ProcessRequest(HttpContext context)
     {
          string prefixText = context.Request.QueryString["q"]; 
          //do your thing here and return as a bar separated list
          StringBuilder sb = new StringBuilder();
          foreach(Results res in results )
            {
                sb.Append(String.Format("{0}|{1}|{2}", +res.Val1, res.Val2, res.Val3));
                sb.Append(Environment.NewLine);
            }
          context.Response.Write(sb.ToString());
     }

JQuery 就在这里(我认为)

必须承认我曾经非常信赖该控制工具包,但是引入 Jquery 后,我发现了很多我认为更好的控件!

只是想我会给你一个不同的选择!

Not an answer specific to the question but I had always used the Ajax Control toolkit autocomplete extender but then I discovered the Jquery one, which in my opinion is much better, and I think you could easily do what you want, although you'd need to assign it to each control in jQuery, but you'd only need 2 functions, one to get the data and one to process the results.

You do something similar to follows:

  $(document).ready(function () {

    $('#<%=txtSearchBox.ClientID%>').autocomplete('/Search.ashx');
    $('#<%=txtSearchBox.ClientID%>').result(function (event, data, formatted) {
        if (data) {

            // Extract the data values
            var name = data[0]; // appears in textbox
            var dataval1= data[1];
            var dataval2= data[2];


            $("#<%=hdndataval1.ClientID%>").val(dataval1);
            $("#<%=hdndataval2 .ClientID%>").val(dataval2);
        }
    });

});

You do have to use hidden fields to store an id, but it autocompletes nicely using a handler.

    public void ProcessRequest(HttpContext context)
     {
          string prefixText = context.Request.QueryString["q"]; 
          //do your thing here and return as a bar separated list
          StringBuilder sb = new StringBuilder();
          foreach(Results res in results )
            {
                sb.Append(String.Format("{0}|{1}|{2}", +res.Val1, res.Val2, res.Val3));
                sb.Append(Environment.NewLine);
            }
          context.Response.Write(sb.ToString());
     }

The JQuery is here (I think)

Must admit I used to swear by that control toolkit, but having been introduced to Jquery I have found loads of controls that I think are much better!

Just thought I'd throw a different option in your direction!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文