Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi! dear frnds i want to make auto complete text box and my code is not working plz tell what is the problem in this code



ASP.NET
<asp:TextBox ID="txtAreaName" runat="server" CssClass="txtArea"  placeholder="Enter Area to Search Dealers" Height="34px" Width="259px"></asp:TextBox>
                       <asp:AutoCompleteExtender ID="AutoCompleteExtender1" ServiceMethod="GetArea" MinimumPrefixLength="2"

                            runat="server" CompletionInterval="100" EnableCaching="true" CompletionSetCount="10" TargetControlID="txtAreaName" FirstRowSelected="true"></asp:AutoCompleteExtender>


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Data;
using System.Configuration;
using System.Web.Services;
using System.Web.Services.Protocols;


namespace OnlinePropertyDealer.MasterPage
{
    public partial class OnlineDealers : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

[System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetArea(string prefixText, int count)
        //[System.Web.Script.Services.ScriptMethod()]
        //[System.Web.Services.WebMethod]
        //public static List<string> GetArea(string prefixText)
        {
            List<string> AreaNames = new List<string>();

            using (OracleConnection con = new OracleConnection())
            {
                con.ConnectionString = ConfigurationManager
                        .ConnectionStrings["conStr"].ConnectionString;
                using (OracleCommand cmd = new OracleCommand())
                {
                    cmd.CommandText = "select area_namr from area_table where " +
                    "area_name like @SearchText + '%'";
                    cmd.Parameters.AddWithValue("@SearchText", prefixText);
                    cmd.Connection = con;
                    con.Open();
                    using (OracleDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            AreaNames.Add(sdr["area_name"].ToString());
                        }
                    }
                    con.Close();
                    return AreaNames.ToArray();
                }
            }
Posted
Updated 7-Jul-14 7:38am
v3
Comments
[no name] 7-Jul-14 6:44am    
"not working" tells us nothing about your problem.

1 solution

It's simple you are missing static
And the reason it supports only static methods is that page is instantiation is not done, if you want to use non static web methods then go for web service(.asmx).

 Collapse | Copy Code
[System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static string[] GetArea(string prefixText, int count)


So any web method of backend you want to use from fronted that may be ajax, jquery...
It needs a static web method
Get more info
static-webmethod-in-code-behind-webform/[^]
 
Share this answer
 
Comments
Member 10927231 7-Jul-14 13:19pm    
thanks dear for your reply...I have tried but problem is still unsolved....

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