vs2008+ajax的AutoCompleteExtender为何无法实现自动文本框功能

sdydwx 2009-06-02 08:49:34
我在VS2008环境下,并安装了ajax control took kit从工具箱中拖入文本框,并给文本框添加了扩展程序(AutoCompleteExtender),并编写了WEB服务WebService.asmx,并在解决方案资源浏览哭中"添加WEB服务引用"加入了Webservice.asmx,并在"添加"窗口中进行了调试,并能成功返回了xml文档,但在浏览器中运行default.aspx,在文本框中录入,发现不出现任何提示,感觉是不是服务没有被调用.请高手指教.

default10.aspx

<%@ Page Language="C#" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" id="head1">
<title>无标题页 </title>
<script type="text/javascript">

function pageLoad() {
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
Enabled="True" ServicePath="WebService.asmx" TargetControlID="TextBox1" ServiceMethod="GetResult" MinimumPrefixLength="1" EnableCaching="true">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>

webservice.asmx

<%@ WebService Language="C#" Class="WebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService()]
public class WebService : System.Web.Services.WebService {
public WebService() {
}

[WebMethod]
public string[] GetResult(string prefixtext,int count)
{
SqlConnection conn = new SqlConnection("server=SERVERCJK;Initial Catalog=cjersist Security Info=True;User ID=saassword=gxhlay");
conn.Open();
SqlCommand comm = new SqlCommand("select top " + count + " 姓名拼音 from bmk where 姓名拼音 like '" + prefixtext + "%'", conn);
SqlDataAdapter adap = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
adap.Fill(ds);
string[] vendors = new string[Math.Min(count, ds.Tables[0].Rows.Count)];
for (int i = 0; i < Math.Min(count, ds.Tables[0].Rows.Count); i++)
{
vendors = ds.Tables[0].Rows.ItemArray[0].ToString();
}
return vendors;
}

}

...全文
409 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
王者永乐 2011-01-18
  • 打赏
  • 举报
回复
您的问题解决了么 怎么解决的啊 我的webconfig文件跟ys_panzer说的一样啊
元元0123 2010-07-29
  • 打赏
  • 举报
回复
谢谢了!ys_panzer
jiangchuandong 2010-01-05
  • 打赏
  • 举报
回复
guanzhu
jin20000 2009-11-04
  • 打赏
  • 举报
回复
额,其实可以看看数据库里有记录吗?
ys_panzer 2009-11-04
  • 打赏
  • 举报
回复
VS2008新建的 ASP.NET WEB应用程序 默认配置文件 WEB.CONFIG 各节点 如下

<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>

<system.web>
<compilation debug="true">
。。。
</compilation>
<authentication mode="Windows"/>
</system.web>
</configuration>
在这个配置下,使用ajax的AutoCompleteExtender 运行后是不起作用的,在程序正确情况下,只可能是配置文件上的问题。对比 VS2005 项目下的WEB.CONFIG 配置后
只需要在配置文件加上两个节点就可以,改过的配置文件如下:(红色字体为添加部分)
VS2008新建的 ASP.NET WEB应用程序 默认配置文件 WEB.CONFIG 各节点 如下

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>


<appSettings/>
<connectionStrings/>

<system.web>
<compilation debug="true">
。。。
</compilation>
<authentication mode="Windows"/>

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>


</system.web>
</configuration>

就是在<configuration> 下 添加一个节点,<system.web>下添加一个节点,运行程序后,就可以实现GOOGLE风格的查询提示列表

sdydwx 2009-06-04
  • 打赏
  • 举报
回复
都按上面做了,web.config里面也有配置。
我的web.config如下,请高手指教是何原因??

<?xml version="1.0"?>
<!--

-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
<add key="selectfields" value="编号, 姓名, 年龄, 性别, 县区, 归类,工作单位, 科班,报名费,报名时间"/>
<add key="localhost.WebService" value="http://localhost:2093/ck/WebService.asmx"/>
</appSettings>
<connectionStrings>
<add name="con1" connectionString="Data Source=SERVERCJK;Initial Catalog=cj;Integrated Security=True;User ID=saassword=gxhlay" providerName="System.Data.SqlClient"/>
<add name="con2" connectionString="Data Source=SERVERCJK;Initial Catalog=cjersist Security Info=True;User ID=saassword=gxhlay" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<!--
-->
<globalization requestEncoding="GB2312" responseEncoding="GB2312"/>
<compilation debug="true" strict="false" explicit="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Generic"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Linq"/>
<add namespace="System.Xml.Linq"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<!--

-->
<authentication mode="Windows"/>
<!--

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
sp_help 2009-06-02
  • 打赏
  • 举报
回复
[WebMethod] 还有查找排序啊
yan286093636 2009-06-02
  • 打赏
  • 举报
回复
public string[] GetResult(string prefixtext,int count)
我记得2008好像有3个参数啊,不能乱删掉啊,

下面这个相当重要。
adap.Fill(DataSet,int(开始的记录索引,一般用0),int(抓取记录数,也就是上面的参数count),string(表名));
yan286093636 2009-06-02
  • 打赏
  • 举报
回复
public string[] GetResult(string prefixtext,int count)
我记得2008好像有3个参数啊,不能乱删掉啊,

下面这个相当重要。
adap.Fill(DataSet,int(开始的记录索引,一般用0),int(抓取记录数,也就是上面的参数count),string(表名));
hs1983 2009-06-02
  • 打赏
  • 举报
回复
参考赵劼老师的ASP.NET AJAX深入浅出系列课程(1):的代码。
1 Accordion 2 AccordionPane 实现多面板,每次都只显示一个,其他收藏起来,可以设置显示隐藏的时间和渐变效果哦 3 AlwaysVisibleControlExtender 这个东西是将VerticalSide的值设置好后无论页面的滚动条滚动,这个目标控件一直都显示在页面的那个位置 4 AnimationExtender 5 AnimationExtenderControlBase 实现控件中内容的动画效果(移动、变化 大小、淡如淡出、变颜色等) 6 AutoCompleteExtender 自动的提示功能,在Google和丁丁地图中都用实现效果,不错的哦 7 CalendarExtender 日历控件 8 CascadingDropDown 级联下拉菜单 9 CollapsiblePanelExtender 点击某个控件,显示一个特定的面板和隐藏那个特定的面板 10 ConfirmButtonExtender 弹出一个确认按钮 11 DraggableListItemExtender 12 DragPanelExtender 拖动控件,将某个面板可以拖动,范围在该页面内 13 DropDownExtender 给任意控件添加下拉菜单 14 DropShadowExtender 将某个面板添加阴影 15 DynamicPopulateExtender 动态生成控件中的内容 16 FilteredTextBoxExtender 可以控制文本框中的输入内容,可以是系统的表达式(FilterType="LowercaseLetters/Numbers")也可以是自定义的(FilterType="Custom") 例如:FilterType="Custom, Numbers" ValidChars="+-=/*()." /> 表示只能输入数字和自定义的"+-=/*()." 这几个符号。。。 17 HoverExtender 18 HoverMenuExtender 鼠标放在某个控件上显示一个特定的面板 19 ListSearchExtender 为下拉菜单添加字母查找功能 20 MaskedEditExtender 21 MaskedEditValidator 输入框格式限定功能 22 ModalPopupExtender 出现模式对话框功能 23 MutuallyExclusiveCheckBoxExtender 多个选项某个选项独占功能 24 NoBot 防爬虫/机器输入功能 25 NumericUpDownExtender 数字值增减,这个效果经常看到哦,Kijiji上面就有的好像 26 PagingBulletedListExtender 按字母顺序的bbs功能 27 PasswordStrength 根据输入的密码客户端提示你输入密码的安全性 28 PopupControlExtender 29 PopupExtender 给任意控件添加一个需要弹出的控件或者面板 30 Rating 评级控件 31 ReorderList 任意添加列表内容并更改列表顺序 32 ResizableControlExtender 控件大小改变 33 RoundedCornersExtender 圆角大小 34 SliderExtender 类似音量大小那种拖动条空间 SlideShowExtender 幻灯片一张张播放图片,没有这个东西的时候做死人,用javascipt中写的 35 TabContainer 36 TabPanel tab控件 这个控件比较常用的哦,有个TabContainer1.ActiveTabIndex = 1; 来设置页面加载的时候显示第几个,默认值为最大的那个,从0开始的哦。 37 TextBoxWatermarkExtender 文本输入框提示文字控件,这个也是友好信息吧,一点就没有了。o(∩_∩)o...哈哈 38 ToggleButtonExtender 可改变的按钮,实际上是一个有图片的checkbox 39 UpdatePanelAnimationExtender 在某个特定的面板中数据更新的时候该面板显示出来的动画效果 40 ValidatorCalloutExtender 增强的输入验证控件

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧