单独运行 asmx文件时能从数据库读取结果,但是运行aspx文件后,就出现不了结果,也不提示错误。不知道怎么回事,请大侠们帮助! 附上代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;一,autowebyuebao.asmx文件
/// <summary>
///autowebyuebao 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
//[System.Web.Script.Services.ScriptService]
public class autowebyuebao : System.Web.Services.WebService
{    public autowebyuebao () 
    {        //如果使用设计的组件,请取消注释以下行 
        //InitializeComponent(); 
    }    [WebMethod]
    public string[] GetSearchTerm(string prefixText, int count)
    {
        DataGg data = new DataGg();
        if (count == 0)
        {
            count = 10;
        }
        using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlServices"].ConnectionString))
        {
            SqlDataAdapter sda = new SqlDataAdapter("select distinct ([LSWLZD_LBBH]+' '+[LSWLZD_WLMC]) from [lc0019999].[LSWLZD] where [LSWLZD_WLMC] like '%" + prefixText + "%'", connection);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            List<string> list = new List<string>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {                list.Add(ds.Tables[0].Rows[i][0].ToString());
            }
            return list.ToArray();
        }
    }
    
}
二、客户端页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Texyboxaspx.aspx.cs" Inherits="Texyboxaspx" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" ScriptMode="Release">
        </asp:ToolkitScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
                ServicePath="~/autowebyuebao.asmx" ServiceMethod="GetSearchTerm" Enabled="True" 
                TargetControlID="TextBox2" MinimumPrefixLength="1"
                CompletionInterval="300" >
            </asp:AutoCompleteExtender>
        </ContentTemplate>
        </asp:UpdatePanel>
     
    
    </div>
    </form>
</body>
</html>

PS:是最简单的那种 文本框动态模糊下拉菜单,类似于百度,不知道为什么没结果,是不是和我的新建的项目有关?新建的项目是website不是webapplication,在webapplication项目下 是好用的,没出现问题。

解决方案 »

  1.   

    <?xml version="1.0" encoding="utf-8" ?> 
    - <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
      <string>0148 铁丝网</string> 
      <string>0102 铁丝</string> 
      <string>0102 镀锌铁丝</string> 
      </ArrayOfString>
    这是单独运行asmx文件时的结果,但是在aspx页面上运行,在Textbox上输入文字后,没有出现下拉猜到模糊查询,不知道是为什么,很疑惑!
      

  2.   

    AJAX控件不用放在UPDAEPANEL里面吧记得
    下面是网上找的一个例子04.<asp:TextBox ID="txtTo" runat="server" Width="500px" AutoPostBack="True"></asp:TextBox>  
    05.<cc1:AutoCompleteExtender ID="AutoCompleteExtenderSearch"   
    06.    MinimumPrefixLength="1"//这是设置输入几个字符才开始调用搜索   
    07.    CompletionInterval="10"   
    08.    runat="server"  
    09.    EnableCaching="true"  
    10.    ServicePath="AutoCompleteSend.asmx"//这是Web Services的路径   
    11.    ServiceMethod="GetToAddress"//这是处理搜索的Web Services下的一个方法   
    12.    TargetControlID="txtTo">//这是对应的TextBox   
    13.</cc1:AutoCompleteExtender>  namespace MySystem.Email  
    24.  
      

  3.   

    你说得这个我也尝试了,可是还是不行,我在web application项目下运行时都好用,能得到结果,不知道为什么在website 项目下,运行aspx,在Textbox上就得不到模糊查询结果了。我觉得问题肯定与website有关,难道AutoCompleteExtender只能在webapplication项目下应用???大神们,求指点!
      

  4.   

    还有我 website下不存在namespace空间的问题