Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
task1.aspx
HTML
<script type="text/javascript" src="jsfiles/validation.js"></script>
    <script type="text/javascript" src="jsfiles/SearchScript.js"></script>
    <link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" />
    <script language="javascript" type="text/javascript" src="windowfiles/dhtmlwindow.js"></script>
    <link href="css/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jsfiles/jquerymin.js" language="javascript"></script>
    <script type="text/javascript" src="jsfiles/jquery-ui.min.js" language="javascript"></script>
    <link href="jquery-ui-1817/development-bundle/demos/demos.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" >

        $(function () {
            var cache = {}, lastXhr;
            $("#Grid_RouteDetailCode_ftxtLocationName").autocomplete({
                minLength: 1,

                source: function (request, response) {
                    var term = request.term;
                    if (term in cache) {
                        response(cache[term]);
                        return;
                    }

                    lastXhr = $.getJSON("GetAutoComplete.aspx?r=" + Math.random() + "&name=" + request.term, request, function (data, status, xhr) {

                        cache[term] = data;

                        if (xhr === lastXhr) {
                            response(data);
                        }
                    });
                },
                select: function (event, ui) {
                    // document.getElementById("birds").value == ui.item.id;
                    //var a = ui.item.id;
                    document.getElementById("locationroute").value = ui.item.id;
                    // document.getElementById("TextBox1").value = ui.item.id;
                    //alert(ui.item.id);
                }
            });

        });


GetAutoComplete.aspx.vb(from the below code am getting json success)

VB
Imports System.Data, System.Data.SqlClient, System.Configuration

Partial Class GetAutoComplete
    Inherits System.Web.UI.Page
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim read As SqlDataReader
    Dim collected_Names As String = ""
    Dim sa As String = ConfigurationManager.ConnectionStrings("AVLS_MDT_HMS_TTK_FINALConnectionString").ToString()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        con = New SqlConnection(sa)
        con.Open()
        Dim str_Name As String = Trim(Request.QueryString("name"))
        Dim query As String = "select  distinct(Location_Name),id from TMS_Route_Detail_Table where Location_Name like '" & str_Name & "%'"
        cmd = New SqlCommand(query, con)
        read = cmd.ExecuteReader()
        Dim shar As String = ""
        collected_Names = "["

        Do While read.Read()
            collected_Names += "{""" & "id"":""" & read(1) & """,""label"":""" & read(0).ToString().ToUpper() & """,""value"":""" & read(1) & """" & "},"
        Loop
        read.Close()
        con.Close()
        If (collected_Names.Length > 1) Then
            collected_Names = collected_Names.Remove(collected_Names.Length - 1, 1)
        End If
        collected_Names += "]"

        Response.Write(collected_Names)
    End Sub
End Class
Posted
Updated 19-Dec-13 1:19am
v2
Comments
Maarten Kools 19-Dec-13 7:41am    
Have you debugged it? Are you getting errors?

I would advise you to use a library/use serialization to create the JSON server side, appending data to a string is going to be terrible to maintain. If you insist to use strings though, use a StringBuilder instead, this will give you much better performance.
Member 10476757 19-Dec-13 7:55am    
yes iam getting json from GetAutoComplete.aspx.vb correct but the thing is the data is getting in response
Maarten Kools 19-Dec-13 7:59am    
Yes, I understand your problem. You can also debug JavaScript though, have you done so? My guess is the line xhr === lastXhr does not result in true.
Member 10476757 19-Dec-13 11:04am    
yes thats where iam not getting
Maarten Kools 19-Dec-13 11:45am    
The sample code on the jQuery site doesn't have that line, why do you have it though? And if you remove it, does it work?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900