我想用数据库使文本框自动完成。我使用了以下代码,但在输出扩展程序中显示了html代码。它甚至不执行函数后面的代码。以下代码我使用了无法正常工作的代码。
ASPx页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="_Default" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
C#代码
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{
using (MySqlConnection conn = new MySqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["conio"].ConnectionString;
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText = "select clientID from clientsDetails where " +
"clientID like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["clientID"].ToString());
}
}
conn.Close();
return customers;
}
}
}
答案 0 :(得分:1)
您正在查看网址上包含TextBox
的网页:
这似乎是由route
映射到页面
CS.aspx
当AutoCompleteExtender
发送AJAX
请求时,它会将其发送到此地址:
这可能是由您设置的某些route
选取的,结果是它没有转到PageMethod
中的CS.aspx.cs
,而是在其他一些地方处理方式。
假设您的CS.aspx
页面位于Web应用程序根文件夹中,您可以通过添加以下内容来修复它:
ServicePath="~/CS.aspx"
给你AutoCompleteExtender
。像这样:
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
ServicePath="~/CS.aspx"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false">
</cc1:AutoCompleteExtender>
答案 1 :(得分:0)
$ dbus-monitor --system type=signal,interface=org.freedesktop.NetworkManager,member=Device{Added,Removed}