Click here to Skip to main content
14,920,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my javascript :

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

C#
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
            {
                           
                //BindRepeater();
                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!!
Posted
Updated 2-Feb-15 0:39am
v2
Comments
TheKarateKid 2-Feb-15 16:51pm
   
did you check whether your are able to select the 'txtSearch' control by jquery? you can try $('[id$=_txtSearch]') or $('#[id$=_txtSearch]') instead of $('#<%=txtSearch.ClientID%>')
Divya Aq 3-Feb-15 2:21am
   
i tried... but its still the same

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