task1.aspx
<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("locationroute").value = ui.item.id;
}
});
});
GetAutoComplete.aspx.vb(from the below code am getting json success)
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