AutoCompleteExtender无法触发Web服务方法...
我的代码在这里..
--------------------------------- -------------------------------
<%@ Page Language =C#AutoEventWireup =trueCodeFile =Emp.aspx.csInherits =Emp%>
<%@ Register Assembly =AjaxControlToolkitNamespace = AjaxControlToolkitTagPrefix =ajax%>
<!DOCTYPE html>
< html xmlns =http://www.w3.org/1999/xhtml>
< head runat =server>
< title> < / title>
< / head>
< body>
< form id =form1runat =server style =background-color:tan>
My code is Here..
----------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Emp.aspx.cs" Inherits="Emp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" style="background-color:tan">
< asp:ScriptManager ID =ScriptManager1 EnablePageMethods =truerunat =server>
< services>
< asp:ServiceReference Path =〜/ WebService.asmx/>
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
<services>
<asp:ServiceReference Path="~/WebService.asmx" />
< asp:Label ID =Label1runat =serverstyle =z-index:1;左:298px;上:157px;位置:绝对;底部:324px;Text =输入名称:>
< asp:TextBox ID =TextBox1runat =serverAutoCompleteType =Disabledstyle =z-index:1 ;左:424px;上:158px;位置:绝对; width:217px;>
< ajax:AutoCompleteExtender ID =AutoCompleteExtender1MinimumPrefixLength =1TargetControlID =TextBox1EnableCaching =trueUseContextKey =TrueCompletionSetCount =10 CompletionInterval =1000ServiceMethod =getValueServicePath =〜/ WebService.asmxrunat =server>
< asp:GridView ID =GridView1runat =serverstyle =z-index:1;左:420px;上:213px;位置:绝对;身高:207px;宽度:316px>
< / form>
< / body>
< / html>
----------------------- ----------------------------------------------
webService.cs
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Text;
使用System.Web.Script.Services;
使用AjaxControlToolkit;
使用System.Web.Services;
//< summary>
/// WebService的摘要说明
///
[WebService(Namespace = http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//允许从脚本调用此Web服务,使用ASP.NET AJAX,取消注释以下行。
[System.Web.Script.Services.ScriptService]
pu blic class WebService:System.Web.Services.WebService {
public WebService(){
/ /如果使用设计的组件,则取消注释以下行
// InitializeComponent();
}
公共字符串HelloWorld(){
返回Hello World;
}
#region获取所有价值
[WebMethod]
public static String [] getValue(string prefixText,int count)
{
DataClassesDataContext dt = new DataClassesDataContext();
var autocompleteData =来自dt.Emp_Details.Where中的数据(U => U.Name.Contains(prefixText))select data.Name;
System.Console。写(DATA:+ autocompleteData);
返回autocompleteData.ToArray();
}
#endregion
[WebMethod]
public List< string> getAllValue()
{
DataClassesDataContext dt = new DataClassesDataContext();
var autocompleteData = from d in dt.Emp_Details select x.Name;
System.Console.Write(DATA:+ autocompleteData);
返回autocompleteData.ToList();
}
}
///给我解决方案...
<asp:Label ID="Label1" runat="server" style="z-index: 1; left: 298px; top: 157px; position: absolute; bottom: 324px;" Text="Enter Name:">
<asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="Disabled" style="z-index: 1; left: 424px; top: 158px; position: absolute; width: 217px;">
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" MinimumPrefixLength="1" TargetControlID="TextBox1" EnableCaching="true" UseContextKey="True" CompletionSetCount="10" CompletionInterval="1000" ServiceMethod="getValue" ServicePath="~/WebService.asmx" runat="server">
<asp:GridView ID="GridView1" runat="server" style="z-index: 1; left: 420px; top: 213px; position: absolute; height: 207px; width: 316px">
</form>
</body>
</html>
---------------------------------------------------------------------
webService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Script.Services;
using AjaxControlToolkit;
using System.Web.Services;
// <summary>
/// Summary description for WebService
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
public string HelloWorld() {
return "Hello World";
}
#region "Getting all value "
[WebMethod]
public static String[] getValue(string prefixText, int count)
{
DataClassesDataContext dt = new DataClassesDataContext();
var autocompleteData = from data in dt.Emp_Details.Where(U => U.Name.Contains(prefixText)) select data.Name;
System.Console.Write("DATA:" + autocompleteData);
return autocompleteData.ToArray();
}
#endregion
[WebMethod]
public List<string> getAllValue()
{
DataClassesDataContext dt = new DataClassesDataContext();
var autocompleteData = from x in dt.Emp_Details select x.Name;
System.Console.Write("DATA:" + autocompleteData);
return autocompleteData.ToList();
}
}
/// Give Me a Solution...
< asp:autocompleteextender id =auotCompleterunat =serverenablecaching =truebehaviorid =AutoCompleteExxmlns:asp =#unknown>
MinimumPrefixLength =2TargetControlID =txtNameServiceMethod =GetCompletionList
CompletionInterval =1000CompletionSetCount =20CompletionListCssClass = autocomplete_completionListElement
CompletionListItemCssClass =autocomplete_listItemCompletionListHighlightedItemCssClass =auto complete_highlightedListItem
DelimiterCharacters =;,:ShowOnlyCurrentWordInCompletionListItem =true>
< animations>
< onshow>
< sequence>
< opacityaction opacity =0>
< hideaction visible =true>
< scriptaction script =//缓存大小并设置初始大小< br mode =hold =/> var behavior =
<asp:autocompleteextender id="auotComplete" runat="server" enablecaching="true" behaviorid="AutoCompleteEx" xmlns:asp="#unknown">
MinimumPrefixLength="2" TargetControlID="txtName" ServiceMethod="GetCompletionList"
CompletionInterval="1000" CompletionSetCount="20" CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true">
<animations>
<onshow>
<sequence>
<opacityaction opacity="0">
<hideaction visible="true">
<scriptaction script="// Cache the size and setup the initial size<br mode=" hold=" /> var behavior =
find('AutoCompleteEx');< br mode =>
< parallel duration =。4>
< fadein>
< length propertykey =heightstartvalue =0>
EndValueScript =
find('AutoCompleteEx');<br mode=">
<parallel duration=".4">
<fadein>
<length propertykey="height" startvalue="0">
EndValueScript="
find('AutoCompleteEx')._height/>
< ; onhide>
< parallel duration =。4>
< fadeout>
< length propertykey =height startvaluescript =< brmode =hold>
find('AutoCompleteEx')._height" />
<onhide>
<parallel duration=".4">
<fadeout>
<length propertykey="height" startvaluescript="<br" mode="hold"> "