问题描述
大家好,
我在Web解决方案中使用AjaxControlToolkit.
我在AjaxEnabled Web应用程序中使用了AutocompleteExtender控件,它可以工作,但是同一代码不适用于简单的应用程序.我也已经灌入了所有必需的dll.
我的aspx页面的代码:
<%@页面语言="C#" AutoEventWireup ="true" CodeFile ="Default.aspx.cs" Inherits ="_ Default"%>
< title>无标题页面
< asp:scriptmanager id ="ScriptManager1" runat ="server">
< services>
< asp:servicereference path ="AutoComplete.asmx">
Hi All,
I am using AjaxControlToolkit in my web solution.
I used AutocompleteExtender control in a AjaxEnabled web app and it worked but the same code is not working for a simple application. I have inculded all the required dll''s as well.
code for my aspx page :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<title>Untitled Page
<asp:scriptmanager id="ScriptManager1" runat="server">
<services>
<asp:servicereference path="AutoComplete.asmx">
< asp:textbox runat ="server" id ="myTextBox" width ="300" autocomplete ="off">
< ajaxtoolkit:自动完成扩展器
runat ="server"
=" id ="autoComplete1" targetcontrolid ="myTextBox" servicepath ="AutoComplete.asmx" servicemethod ="GetCompletionList" minimumprefixlength ="2" completeinterval ="1000" enablecaching ="true" completesetcount ="12">
<asp:textbox runat="server" id="myTextBox" width="300" autocomplete="off">
<ajaxtoolkit:autocompleteextender
runat="server"
="" id="autoComplete1" targetcontrolid="myTextBox" servicepath="AutoComplete.asmx" servicemethod="GetCompletionList" minimumprefixlength="2" completioninterval="1000" enablecaching="true" completionsetcount="12">
我的网络服务的代码:
使用系统;
使用System.Collections.Generic;
使用System.Web.Services;
使用System.Data.SqlClient;
使用System.Data;
[WebService(Namespace ="http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
公共类AutoComplete:WebService
{
公共AutoComplete()
{
}
[WebMethod]
公共字符串[] GetCompletionList(字符串prefixText,整数计数)
{
字符串str =//sql连接字符串
SqlConnection conn =新的SqlConnection(str);
SqlCommand cmd =新的SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText ="Ajax_GetCustomerList";
cmd.Parameters.Add("@ customerNameSubString",SqlDbType.VarChar,100).Value = prefixText.ToString();
SqlDataAdapter da =新的SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"customerSubStringList");
string [] chk =新字符串[ds.Tables [0] .Rows.Count];
int i = 0;
foreach(ds.Tables [0] .Rows中的DataRow dr)
{
chk [i] = dr [0] .ToString();
i ++;
}
return chk;
}
}
请帮帮我.
问候,
Divya
code for my webservice :
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
public AutoComplete()
{
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
string str = // sql connection string
SqlConnection conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = "Ajax_GetCustomerList";
cmd.Parameters.Add("@customerNameSubString", SqlDbType.VarChar, 100).Value = prefixText.ToString();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "customerSubStringList");
string[]chk = new string[ds.Tables[0].Rows.Count];
int i = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
chk[i] = dr[0].ToString();
i++;
}
return chk;
}
}
Please help me.
Regards,
Divya
推荐答案
<asp:ScriptManager ID="ScriptManager1" runat="server">
<services>
<asp:ServiceReference Path="AutoComplete.asmx"></asp:ServiceReference>
</services>
</asp:ScriptManager>
2)
2)
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count)
MS Sample Url http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete .aspx [ ^ ]
MS Sample Url http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx[^]
这篇关于AutoCompleteExtender没有在简单的Web应用程序中调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!