具有jquery自动完成功能的多用户控件未显示所有列表

时间:2011-09-12 07:31:50

标签: jquery asp.net user-controls autocomplete

在我的asp.net C#网站上,我需要为某些文本字段添加自动填充功能。为此,我正在使用jquery自动完成。

我有一个父用户控件,还有两个子用户控件(仅限文本框)。三个用户控件都有自己的自动完成列表。

问题是,当我运行程序时,只有一个自动完成列表显示项目列表。其他两个人都沉默了!。

如果有人有任何想法,请在此处分享。

<%@ Control Language =“C#”AutoEventWireup =“true”CodeFile =“Contact.ascx.cs”Inherits =“Controls_Contact”%> <%@ Register Src =“ContactSub.ascx”TagName =“ContactSub”TagPrefix =“ContactSub_UC”%>

<script type="text/javascript">
function LoadList_contact()
{
    alert("check main");
    $("#<%= ContactSurnameTextBox.ClientID %>").autocomplete({
        source: "../ashx/AutoComplete_Contacts.ashx",
        minLength: 1,
        select: function (event, ui)
        {
            $(this).next().val(ui.item.id);
            $("#<%= ContactIdTextBox.ClientID %>")[0].value = ui.item.id;
            __doPostBack('<%= ContactSurnameTextBox.ClientID %>', '');
        },

        search: function (event, ui)
        {
            $(this).next().val('');
            $("#<%= ContactIdTextBox.ClientID %>")[0].value = '';
        }

    })
    .data("autocomplete")._renderItem = function (ul, item)
    {
        return $("<li></li>")
            .data("item.autocomplete", item)
            .append("<a><table cellpadding='0' cellspacing='0' border='0' width='250'><tr><td width='*' valign='top' align='left'>" + item.value + "</td><td width='50px' valign='top' align='left'></td></tr></table></a>")
            .appendTo(ul);
    };
}

<asp:TableRow>
    <asp:TableCell ID="ContactSubCell" runat="server">
        <ContactSub_UC:ContactSub ID="ContactSub" runat="server" />
    </asp:TableCell>
</asp:TableRow>


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactSub.ascx.cs" Inherits="Controls_ContactSub" %>

&lt;%@ Register src =“ProductsTextbox.ascx”tagname =“ProductsTextbox”tagprefix =“ProductsTextbox_UC”%&gt; &lt;%@ Register src =“BrandLine.ascx”tagname =“BrandLine”tagprefix =“BrandLine_UC”%&gt;

<asp:TableCell ColumnSpan="3">
    <BrandLine_UC:BrandLine ID="BrandLine" runat="server" />
</asp:TableCell>

<asp:TableCell ColumnSpan="3">
    <ProductsTextbox_UC:BrandLine ID="ProductsTextbox" runat="server" />
</asp:TableCell>

由于

RBZ

1 个答案:

答案 0 :(得分:0)

<input id="first_AT"><input id="second_AT">

对于每个输入提供不同的id或类。

$('#first_AT, #second_AT').autocomplete();