Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code is AT AutoComplete.aspx page,
HTML
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    <services>
        <asp:ServiceReference Path="~/AutoComplete.asmx" />
    </services>
    <asp:TextBox ID="TxtCompName" Width="350px" runat="server" AutoPostBack="True" 
        ontextchanged="TxtCompName_TextChanged"/>

    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
        CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" CompletionListItemCssClass="autocomplete_listItem"        
        CompletionListCssClass="autocomplete_completionListElement" 
        Enabled="True" ServiceMethod="GetCompletionList" 
        ServicePath="~/AutoComplete.asmx" TargetControlID="TxtCompName" UseContextKey="True" 
        CompletionInterval="100" DelimiterCharacters="" CompletionSetCount="20" MinimumPrefixLength="1" />

the web services file is present in my projet:(AutoComplete.asmx) and Web servics Code Behind(AutoComplete.cs) is in app_code folder.
The code is:
C#
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
    public AutoComplete()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public static string[] GetCompletionList(string prefixText, string contextKey)
    {
        SqlConnection conn;
        SqlCommand cmd;
        string cmdString = "SELECT comp_name FROM tbl_admin_Brand WHERE comp_name LIKE'" + prefixText + "%'";

        conn = new SqlConnection("Data Source=INDIA\\SQLEXPRESS;Initial Catalog=BrandMutual;User ID=sa1;Password=123");
        cmd = new SqlCommand(cmdString, conn);
        conn.Open();
        SqlDataReader myReader;
        List<string> returnData = new List<string>();
        myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        while (myReader.Read())
        {
            returnData.Add(myReader["comp_name"].ToString());
        }
        return returnData.ToArray();
    }
}


But my problem is I unable to access Webservices,so my auto extendor give nothing,

And if i put web services code at AutoComplete.cs page then it work fine,
So what can i do.
Posted
Updated 30-Apr-13 2:07am
v5
Comments
Prasad Khandekar 26-Apr-13 3:55am    
Please have a look at (http://www.aspdotnet-suresh.com/2011/03/how-to-implement-auto-complete-textbox.html) this sample. Try removing ~/ from service path.
ChienVH 4-May-13 13:00pm    
Before running your asp.net code then your service need to be started.
Arun kumar Gauttam 7-May-13 4:34am    
and how i start web services ,before running asp.net code
ChienVH 7-May-13 9:54am    
Just right click on your webservice file, then click to View In browser(if you run at local)

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