I am working on autocomplete functionality with textbox using HttpHandler. But i have got error like as cannot call methods on autocomplete prior to initialization; attempted to call method 'AutoCompleteHandler.ashx'. I am using following code.
JQuery Libraries-
JSCode-
$(document).ready(function () {
$('#<%=txtSearch.ClientID%>').autocomplete('AutoCompleteHandler.ashx');
});
$('#<%=txtSearch.ClientID%>').autocomplete('AutoCompleteHandler.ashx');
});
AutoCompleteHandler.ashx code is following-
<%@ WebHandler Language="VB" Class="AutoCompleteHandler" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Public Class AutoCompleteHandler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World")
Dim SHGName As String = context.Request.QueryString("q")
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("YesBankStr").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "Select cSHGName from SHG where cSHGName like ''+@SearchSHGName+'%'"
cmd.Parameters.AddWithValue("@SearchSHGName", SHGName)
cmd.Connection = conn
Dim sb As StringBuilder = New StringBuilder
conn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
sb.Append(sdr("cSHGName")) _
.Append(Environment.NewLine)
End While
conn.Close()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Public Class AutoCompleteHandler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'context.Response.ContentType = "text/plain"
'context.Response.Write("Hello World")
Dim SHGName As String = context.Request.QueryString("q")
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("YesBankStr").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "Select cSHGName from SHG where cSHGName like ''+@SearchSHGName+'%'"
cmd.Parameters.AddWithValue("@SearchSHGName", SHGName)
cmd.Connection = conn
Dim sb As StringBuilder = New StringBuilder
conn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
sb.Append(sdr("cSHGName")) _
.Append(Environment.NewLine)
End While
conn.Close()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
kalu singh raoPosted Jan 8, 2015, 12:41 AM
Vithal WadjePosted Jan 7, 2015, 11:01 PM