Just put below lines in head section of page :
<script type="text/javascript">
$(function () {
initializer();
});
var prmInstance = Sys.WebForms.PageRequestManager.getInstance();
prmInstance.add_endRequest(function () {
//you need to re-bind your jquery events here
initializer();
});
function initializer() {
$("#<%=txtPartyNameSearch.ClientID%>").autocomplete('autoCmp.ashx')
.result(function (event, data, formatted) {
if (data) {
$("#<%= hidrefguagecode.ClientID %>").val(data[1]);
}
else {
$("#<%= hidrefguagecode.ClientID %>").val('-1');
}
});
}
</script>
Code for text box:
<asp:TextBox ID="txtPartyNameSearch" runat="server" CssClass="TextBoxNew">
</asp:TextBox>
<asp:HiddenField ID="hidrefguagecode" runat="server" />
And add ashx file in your solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
namespace CS.WEB.UI
{
/// <summary>
/// Summary description for AutoCmp
/// </summary>
public class AutoCmp : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["ConnectionStr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand()){
cmd.CommandText = "select PartyName from tblCustomerDetail where PartyName LIKE '" + prefixText + "%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
StringBuilder sb = new StringBuilder();
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(sdr["PartyName"])
.Append(Environment.NewLine);
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}