开发者

Jquery Auto Complete in asp.net

i want to use jquery ui auto complete plugin in asp.net. this is my behind code :

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim locations As String() = New String() {"Las Vegas", "Los Angeles", "Tampa", "New York", "s", "sss"}
    Dim jsArray As String = GetJSArrayForVBArray(locations)
    Me.ClientScript.RegisterArrayDeclaration("usernames", jsArray)
End Sub
Private Function GetJSArrayForVBArray(ByVal vbArray As String()) As String
    Dim myResult As New St开发者_JAVA技巧ringBuilder()
    For Each item As String In vbArray
        With myResult
            .Append(",'" & item & "'")
        End With
    Next
    If (myResult.Length > 0) Then
        Return myResult.ToString().Substring(1)
    Else
        Return ""
    End If
End Function

this is html code :

 <script type="text/javascript">
    $(function () {
        var availableTags = new Array();
        $("#tags").autocomplete({
            source: availableTags
        });
    });
</script>

<label for="tags">Tags: </label>
<input id="tags" />

what is the problem? it does not work. when i filling array in aspx page it works but when i want to fill in behind code not. thanks.


Try changing your JS to this:

<script type="text/javascript">
$(function () {
    $("#tags").autocomplete({
        source: usernames
    });
});
</script>

If I'm guessing at your .Net code correctly, you're registering "usernames" as the javascript array, but trying to use the empty 'availableTags' as your autocomplete source.

Note: this may be completely off-base here - I haven't actually used ClientScript.RegisterArrayDeclaration or the jQuery autocomplete plugin in code I've written before.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜