自动完成控制不起作用..这是我的代码 [英] auto complete control is not working..this is my code

查看:70
本文介绍了自动完成控制不起作用..这是我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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: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>







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();
                }
            }

推荐答案

很简单,你缺少静电

和它只支持静态方法的原因是页面是实例化没有完成,如果你想使用非静态网络方法,那就去网络服务(.asmx)。



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)





所以你想从前端使用的任何后端Web方法可能是ajax,jquery ......

它需要静态网络方法

获取更多信息

static-webmethod-in-code-behind-webform / [ ^ ]


这篇关于自动完成控制不起作用..这是我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆