I've modified some code from my
post to solve your problem.
But before you try this code I want to clear that this approach is only saving your network traffic between browser and IIS and doing things better that a update panel does. So if there any network related issues/lagging at your DB server level then It
wont help much and I'll suggest your to fine tune your SP/Tables/Indexes instead trying this.
Copy/paste below code in new test page and try it prior actual implementation. Hope it will help.
Note - Dont forget to add
EnableEventValidation="false" in your @page directive
<head runat="server">
<title></title>
<script src="jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jquery.tmpl.js" type="text/javascript"></script>
<script type="text/javascript">
function getsuggestions(event) {
$('#<%=txtValue.ClientID%>').val('');
var value = $('#' + '<%=txtnames.ClientID%>').val();
if (value.length > 0) {
$.ajax({
type: "POST",
url: "AutoComplete.aspx/getSuggestions",
data: "{'keyword':'" + value + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg, sd, fg) {
if (msg.d && msg.d.length > 0) {
$("#" + '<%=ddlSuggestion.ClientID%>').children().remove();
$("#tmplSuggestions").tmpl(msg.d).appendTo("#" + '<%=ddlSuggestion.ClientID%>');
$('#<%=txtValue.ClientID%>').val($('#<%=ddlSuggestion.ClientID%> option:eq(0)').val());
}
else {
$('#<%=txtValue.ClientID%>').val('');
}
},
error: function (gfh, ghg) {
alert("error");
},
complete: function (eret, tytyt) {
}
});
}
}
function setvalue() {
$('#<%=txtValue.ClientID%>').val('');
$('#<%=txtValue.ClientID%>').val($('#<%=ddlSuggestion.ClientID%>').val());
}
$(document).ready(function (){
$('#<%=txtValue.ClientID%>').val('');
})
</script>
<script id="tmplSuggestions" type="text/html">
<option value="${Value}">${Name}</option>
</script>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
namespace TestApp
{
public partial class AutoComplete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static object getSuggestions(string keyword)
{
DataTable dtSugg = GetSuggestionsFromDB();
var list = from dr in dtSugg.AsEnumerable()
where dr.Field<string>("Name").Contains(keyword)
select new { Name = dr.Field<string>("Name"), Value = dr.Field<string>("Value") };
return list;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string msg =string.Empty;
if (txtValue.Text == string.Empty)
{
msg = "Please select one value";
}
else
{
msg = txtValue.Text;
}
Response.Write(msg);
}
protected static DataTable GetSuggestionsFromDB()
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Name");
DataColumn dc1 = new DataColumn("Value");
dt.Columns.Add(dc);
dt.Columns.Add(dc1);
dt.Rows.Add("john", "john");
dt.Rows.Add("jerry", "jerry");
dt.Rows.Add("jonathan", "jonathan");
dt.Rows.Add("micheal", "micheal");
dt.Rows.Add("mike", "mike");
dt.Rows.Add("michelle", "michelle");
dt.Rows.Add("cindy", "cindy");
dt.Rows.Add("campbell", "campbell");
dt.Rows.Add("paul", "paul");
dt.Rows.Add("petty", "petty");
dt.Rows.Add("paurus", "paurus");
dt.Rows.Add("Edward", "Edward");
dt.Rows.Add("Abbey", "Abbey");
dt.Rows.Add("Henry", "Henry");
dt.Rows.Add("Derek", "Derek");
dt.Rows.Add("Diane", "Diane");
dt.Rows.Add("Edwin", "Edwin");
dt.Rows.Add("Abbot", "Abbot");
dt.Rows.Add("Jack", "Jack");
dt.Rows.Add("Abbott", "Abbott");
dt.Rows.Add("Shirley", "Shirley");
dt.Rows.Add("Tony", "Tony");
return dt;
}
}
}