Ajax Auto Complete Extender for social networking website using ajax



Ajax Auto Complete Extender for social networking website using ajax



  1. Ajax Auto complete extender is a part of ajax tool kit and it is used to show suggestions so that any user does not have to type the complete sentence or word.
  2.  In our Social Networking project HeartBeat we have Autocomplete extender to show friend name suggestions when user types any name. 
  3. To Accomplish this task we have made use of web service with a function in it which will return the result with real time effect.

WebService.cs C# Code:

  1. Open WebService.cs User Control Which You have created in AppCode Folder. In the Source of WebService.cs file you can add the following piece of code given below.
  2. On Opening the Webservice you will find that there is a hello world function by defualt it comes with every new webservice that is added.
  3. We have created a function named as SearchFriends which will receive text in string format and return an array of string.Through this webservice we have made a database connection and we are searching the name of the registered user using like operator.
  4. We are storing the retrived results in a datatable and after processing the datatable using foreach loop we are returning an array of strings


using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Web.Configuration;


[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{

    public WebService()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public string[] SearchFriends(string prefixText)
    {
        string connstring = Database.connString.ToString();
        string sql = "Select * from Register Where Name like @prefixText";
        SqlDataAdapter da = new SqlDataAdapter(sql, connstring);
        da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
        DataTable dt = new DataTable();
        da.Fill(dt);
        string[] items = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            items.SetValue(dr["Name"].ToString(), i);
            i++;
        }
        return items;
    }

}


1 comments: