You must Sign In to post a response.
  • Category: ASP.NET

    Autocomplete textbox using jquery in asp net

    For autocomplete textbox i am using asp.net GenericHandler.ashx, jquery, StoreProcedure.


    GenericHandler.ashx
    ------------------------
    public void ProcessRequest(HttpContext context)
    {
    string term = context.Request["term"] ?? "";
    List<string> listCustomerName = new List<string>();

    string cs = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

    using (SqlConnection conn = new SqlConnection(cs))
    {
    SqlCommand cmd = new SqlCommand("searchCustomerDetails",conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add(new SqlParameter()
    {
    ParameterName ="@term",
    Value =term
    });
    conn.Open();
    SqlDataReader rdr = cmd.ExecuteReader();
    while (rdr.Read())
    {
    listCustomerName.Add(rdr["CustomerName"].ToString());
    }
    }
    JavaScriptSerializer js = new JavaScriptSerializer();
    context.Response.Write(js.Serialize(listCustomerName));
    }

    JQuery
    --------
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <link href="SearchCustomer/jquery-ui.css" rel="stylesheet" />
    <script src="SearchCustomer/jquery-ui.js"></script>

    <script type="text/javascript">
    $(document).ready(function () {
    $('#txtName').autocomplete({
    source: 'CustomerHandler.ashx'
    });
    });

    </script>

    Store Procedure
    ------------------

    create proc searchCustomerDetails
    (
    @term nvarchar(50)
    )
    as
    begin
    select CustomerName from tblCustomerDetails
    where CustomerName like @term + '%'
    end



    above code works fine in normal asp.net web page for auto suggestion through textbox but i am trying to add this code on Content page of master page it is not working.

    There are many ways to do same task, kindly give me solution for above code.
  • #769685
    you can refer parent object while you adding from content page in your script and that may give solution for you problem.

    also, if you can share us the error details then that might give hint to suggest suitable solution.

    Thanks!
    B.Ramana Reddy


  • Sign In to post your comments