This is my javascript :
<script src="js/jquery.js" type="text/javascript"></script>
<link href="css/default.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
$('#<%=txtSearch.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "Members1.aspx/GetName",
data: "{ 'pre':'" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return { value: item }
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
});
});
</script>
this is my CS code
public partial class CP_News : System.Web.UI.Page
{
public string msg2;
static string search = "";
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["name"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
allBindRepeater();
}
}
search = DropDownListSearch.SelectedItem.Text;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<string> GetName(string pre)
{
List<string> allSearchName = new List<string>();
string key = search;
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["ConnectionString2"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
conn.Open();
if (key == "Mobile")
{
cmd.CommandText = "SELECT ContactNo FROM PersonalInformation where " +
"ContactNo like N'" + pre + "%'";
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
allSearchName.Add(string.Format("{0}", sdr["ContactNo"]));
}
}
}
conn.Close();
}
return allSearchName;
}
}
for the textbox :
<asp:TextBox ID="txtSearch" runat="server" >
After testing using breakpoint, I found that the control doesn't move inside the "Getname" Function while typing in the textbox.
Pleas let me know where m i wrong!!