0

I've created a user control which is very basic, It's a asp.net text box with JQuery autocomplete functionality attached. This is all defined in the aspx page not programatically.

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script type="text/jscript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>


  <script type="text/jscript" >


      $(function() {

    $(".tb").autocomplete({

        source: [ <%=GetAutoCompleteData%> ],

    });

});
  </script>


  <asp:TextBox ID="TBAUTO" class="tb" runat="server"></asp:TextBox>
  <asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click"></asp:Button>

This works perfectly well when one control is on a page. However when i add another they both seem to have the same data which shouldn't be the case.

When i check what is rendered to the page it's as i expect but they both contain the same data when the auto complete functionality kicks in

This is what is rendered to the page This is what is rendered to the page

Any help would be appreciated.

enter image description here

4

2 回答 2

1

从我可以看到你正在使用 $(".tb") 将你的自动完成与一个类链接起来,这将是一组一个或多个 dom 元素。尝试使用 # 而不是如下所示

    $(function() {      
        $("#<%= TBAUTO.ClientID %>").autocomplete({          
        source: [ <%=GetAutoCompleteData%> ],       
        });  
    });   
于 2012-09-14T09:38:10.597 回答
0

由于我对上述解决方案没有运气,而且我知道 $(function() {

$(".tb").autocomplete({ 

    source: [ <%=GetAutoCompleteData%> ], 

}); 

工作我只是在我的代码中将页面加载时的 CssClass 设置为给定的变量(DataFilter),然后

$(函数(){

$(".<%=DataFilter%>").autocomplete({

    source: [ <%=GetAutoCompleteData%> ],

});
于 2012-09-14T10:56:38.603 回答