Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on the AutoComplete Extender.I already wrote the webservice for the autosuggestion and i also initialed the extendor and set its properties.So when i am running the code from the webservice,iam getting the needed suggestions.But when running the code from the default.aspx iam getting no results.So my question is that do i need to call the webservice from the default.aspx by using the Text_Changed event for the textbox ?

This is the code that iam using :

in the HTML :
<br />
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><br />
<br />
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head  runat="server"><br />
    <title>Untitled Page</title><br />
</head><br />
<br />
<body><br />
    <form id="form1"  runat="server"><br />
    <div><br />
    <br />
        <asp:TextBox ID="TextBox1" runat="server" ><br />
    </div><br />
    <br />
     <asp:autocompleteextender ID="Autocompleteextender1" runat="server"<br />
     <br />
     TargetControlID="TextBox1"<br />
    ServicePath="MyWebService.asmx"<br />
    ServiceMethod="AutoSuggest"<br />
    MinimumPrefixLength="1" <br />
   CompletionSetCount="10" ><br />
    <br />
    <br />
        <br />
    <br />
    <br />
    <asp:ScriptManager ID="ScriptManager2" runat="server" > <br />
    <services> <br />
    <asp:ServiceReference Path="MyWebService.asmx" /> <br />
    </services> <br />
     <br />
<br />
     <br /><br />
     <br />
    </form><br />
    <br />
</body><br />
</html><br />
<br />


And in the Webservice :
<br />
using System;<br />
using System.Collections;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Services;<br />
using System.Web.Services.Protocols;<br />
using System.Xml.Linq;<br />
using System.Data;<br />
using System.Collections;<br />
using System.Xml;<br />
/// <summary><br />
/// Summary description for MyWebService<br />
/// </summary><br />
[WebService(Namespace = "http://zarif.org/")]<br />
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <br />
 [System.Web.Script.Services.ScriptService]<br />
public class MyWebService : System.Web.Services.WebService {<br />
<br />
    public MyWebService () {<br />
<br />
        //Uncomment the following line if using designed components <br />
        //InitializeComponent(); <br />
    }<br />
<br />
    [WebMethod]<br />
    <br />
    public string[] AutoSuggest(string prefixText, int count)<br />
    {<br />
        DataSet ds = new DataSet();<br />
        DataTable dt=new DataTable();<br />
        ds.ReadXml(Server.MapPath("~/App_Data/register.xml"));<br />
        dt = ds.Tables[0];<br />
        <br />
        <br />
        DataView dvStates = new DataView(dt, string.Format("name like '{0}%'", prefixText), "", DataViewRowState.CurrentRows);<br />
<br />
        System.Collections.Generic.List<string> items = new System.Collections.Generic.List<string>(count);<br />
<br />
        for (int i = 0; i < dvStates.Count; i++)<br />
        {<br />
            items.Add(dvStates[i]["name"].ToString());<br />
        }<br />
<br />
        return items.ToArray();<br />
    } <br />
<br />
    <br />
}<br />
</string></string>
Posted
Updated 25-Jan-11 3:50am
v2

1 solution

Not sure, what your default.aspx does. Better, you post the code snippet.

Also have a look http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete.aspx, they have very well described how to do this.
 
Share this answer
 
Comments
ahsan sarfraz 26-Jan-11 0:05am    
Nice link

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