Click here to Skip to main content
14,924,138 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here my textbox not autocomplete it shows no error why......... Search.ashx
<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Web;
using System.Text;
using System.Data.SqlClient;

public class Search : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string searchText = context.Request.QueryString["q"];

        SqlConnection con = new SqlConnection("Data Source=GETDES_06;Initial Catalog=prakash;User ID=sa;Password=sql@2012");

        con.Open();
        SqlCommand cmd = new SqlCommand("Select username,imagename from getezee where username Like @Search + '%'", con);
        cmd.Parameters.AddWithValue("@Search", searchText);
        StringBuilder sb = new StringBuilder();
        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                sb.Append(string.Format("{0},{1}{2}", dr["username"], dr["imagename"], Environment.NewLine));
            }
        }
        con.Close();
        context.Response.Write(sb.ToString());
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

asp.code
 <script src="scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="scripts/jquery.autocomplete.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("<%#txtSearch.ClientID%>").autocomplete("Search.ashx", {
        width: 200,
        formatItem: function (data, i, n, value) {

            return "<img style = 'width:50px;height:50px' src= userimage/" + value.split(",")[1] + "'/> " + value.split(",")[0];
        },
        formatResult: function (data, value) {
            return value.split(",")[0];
        }
    });
});
    </script> 
<div class="auto-style8">
                    <asp:TextBox ID="txtSearch" runat="server" CssClass="style16" Height="25px" placeholder="Search your idea" Width="314px" ></asp:TextBox>
                    <asp:Button ID="bt1" runat="server" Text="Search" Height="32px" CssClass="style16" BackColor="#CC9900" Width="74px" OnClick="bt1_Click" />
                   </div>
Posted
Updated 8-Oct-14 22:16pm
v3
Comments
Member 10918596 9-Oct-14 3:54am
   
give valuable comment

1 solution

Are you sure that
$("<%#txtSearch.ClientID%>")
selects your textbox?
shouldn't it be:
$("#<%#txtSearch.ClientID%>")
?
   

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




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