AJAX自动完成扩展不工作 [英] ajax autocomplete extender is not working
本文介绍了AJAX自动完成扩展不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对文本的autocompleate扩展,显示记录从数据库列表,但whern我点击texbox并开始键入什么happned。我的HTML code是
< ASP:文本框ID =TextBox1的=服务器>< / ASP:文本框>
< ASP:AutoCompleteExtender ID =TextBox1_AutoCompleteExtender=服务器
启用=真的TargetControlID =TextBox1的ServicePath =〜/ WebService.asmx
ServiceMethod =GetCompletionList
最低prefixLength =2
CompletionInterval =1000
EnableCaching =真
CompletionSetCount =20
DelimiterCharacters =;,
ShowOnlyCurrentWordInCompletionListItem =真正的>
< / ASP:AutoCompleteExtender>
和我的Web服务
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.Services;
使用System.Data这;
使用MySql.Data.MySqlClient;
使用System.Configuration;
///<总结>
///摘要说明的WebService
///< /总结>
[WebService的(命名空间=http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)
//要允许此Web服务从脚本调用,使用ASP.NET AJAX,取消注释以下行。
// [System.Web.Script.Services.ScriptService]
公共类的WebService:System.Web.Services.WebService {
公开的WebService(){
//取消注释以下行,如果使用设计的组件
//的InitializeComponent();
}
[WebMethod的]
公共静态列表<字符串> GetCompletionList(字符串prefixText,诠释计数)
{
的MySqlConnection CON =新的MySqlConnection(ConfigurationManager.AppSettings [CN]);
如果(con.State == ConnectionState.Closed)
con.Open();
的MySqlCommand CMD =新的MySqlCommand(选择gotra从tbgotra WHERE gotra LIKE'%+ prefixText +%',CON);
名单<字符串> K =新的名单,其中,串>();
使用(MySqlDataReader中SDR = cmd.ExecuteReader())
{
而(sdr.Read())
{
k.Add(SDR [gotra]的ToString());
}
}
con.Close();
返回K表;
}
}
解决方案
尝试加入这一行,我记得我有同样的问题曾经在那里工作过,我在本地,但不是生活。
[WebMethod的]
[System.Web.Script.Services.ScriptMethod]< - 添加这一行
公共静态列表<字符串> GetCompletionList(字符串prefixText,诠释计数)
....
I have an autocompleate extender on textbox which shows records as a list from database but whern I click on texbox and start typing nothing happned. my html code is
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
Enabled="True" TargetControlID="TextBox1" ServicePath="~/WebService.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true" >
</asp:AutoCompleteExtender>
And my web service is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
/// <summary>
/// Summary description for WebService
/// </summary>
[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();
}
[WebMethod]
public static List<string> GetCompletionList(string prefixText, int count)
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["cn"]);
if (con.State == ConnectionState.Closed)
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT gotra FROM tbgotra WHERE gotra LIKE '%" + prefixText + "%'",con);
List<string> k = new List<string>();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
k.Add(sdr["gotra"].ToString());
}
}
con.Close();
return k;
}
}
解决方案
Try adding this line, i remember i had the same problem once where it worked for me locally but not live.
[WebMethod]
[System.Web.Script.Services.ScriptMethod] <-- Add this line
public static List<string> GetCompletionList(string prefixText, int count)
....
这篇关于AJAX自动完成扩展不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文