C# asp.net中的自动完成jquery,源代码隐藏

C# asp.net中的自动完成jquery,源代码隐藏,c#,jquery,asp.net,jquery-ui,sharepoint,C#,Jquery,Asp.net,Jquery Ui,Sharepoint,虽然在这个论坛中有很多jquery自动完成代码。但是,我还没有找到任何适合我的SharePoint/ASP.NET网页案例的内容。我跟着火车走。这很有帮助。但是请看 我的代码: <asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"> <link href="http://ajax.googleapis.com/ajax/libs/jqueryu

虽然在这个论坛中有很多jquery自动完成代码。但是,我还没有找到任何适合我的SharePoint/ASP.NET网页案例的内容。我跟着火车走。这很有帮助。但是请看

我的代码:

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        $("asp:TextBox#TextBox3").autocomplete({
            source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
        });
    });

</script>
 </asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table>
      <tr><td>
        <asp:Label ID="Label4" runat="server" Text="Qode"></asp:Label></td><td>
           <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

        </td></tr>
</table>
让我们在代码隐藏中说:

        string[] source = new string[5];
        source[0] = "c++";
        source[1] = "java";
        source[2] = "php";
        source[3] = "coldfusion";
        source[4] = "javascript";
那么如何将数组传递给jquery代码呢?
非常感谢。

关于您的第一个问题,如果您使用的是ASP.net版本4或更高版本,您可以将文本框的ClientID设置为“static”,这将强制服务器呈现与服务器ID相同的ClientID。然后您可以在jQuery代码中正常引用它


),其中包含如何使用库的示例。

我使用了$(document).ready(function(){$(“”).autocomplete({但它不起作用。请再次检查我的代码,我在选择器中有一个输入错误。如果您不能使用第三方组件(如jason.net),则在前面应该有一个#。如果您的字符串是动态的,则可以选择宿主一个瘦页方法,然后使用ajax动态地获取结果。请务必注意into Roman关于对PageMethod使用Ajax调用的想法。这将为您的代码提供更大的灵活性,使您的自动完成由SQL、XML等数据驱动。JavaScriptSerializer类肯定也能很好地工作,但由于我接管的早期项目,我刚刚习惯使用Json.net。请记住该JavaScriptSerializer是一个.NET3.5添加项,因此如果您使用的是较旧版本的框架,您将无法在本机上使用它。
        string[] source = new string[5];
        source[0] = "c++";
        source[1] = "java";
        source[2] = "php";
        source[3] = "coldfusion";
        source[4] = "javascript";
$("#TextBox3")  // select your text box with standard jQuery id selector
$("#<%= Textbox3.ClientID %>")