Hi,
I want to use jquery autocomplete from database in asp.net. I got it working except the minLength option. As shown in the following code, I tried a few ways but couldn't get minLength option working. Please shed light on this. Thank you.
Here is my code:
I want to use jquery autocomplete from database in asp.net. I got it working except the minLength option. As shown in the following code, I tried a few ways but couldn't get minLength option working. Please shed light on this. Thank you.
Here is my code:
Code:
<script src="../../../jquery/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript" src="../../../jquery/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// $(".selector").autocomplete({ minLength: 0 });
// $(".selector").autocomplete("option", "minLength", 4);
$("#<%=TextBox1.ClientID%>").autocomplete({ minLength: 4 });
$("#<%=TextBox1.ClientID%>").autocomplete("option", "minLength", 4);
$("#<%=TextBox1.ClientID%>").autocomplete("AutocompleteData.ashx");
// $("#<%=TextBox1.ClientID%>").autocomplete({ source: "AutocompleteData.ashx", minLength: 4 });
});
</script>
Code:
<%@ WebHandler Language="C#" Class="AutocompleteData" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class AutocompleteData : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string schoolname = context.Request.QueryString["q"];
string sql = <my query>;
using (SqlConnection connection = new SqlConnection(
System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
context.Response.Write(reader.GetString(0) + Environment.NewLine);
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}