编辑:这是编辑后的控制文件(control.ascx):
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Sale.ascx.cs" Inherits="Enmasse.Modules.Demo_Enmasse.Sale" %>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=txtuser.ClientID%>").autocomplete('<%=ResolveUrl("Search_Username.ashx")%>');
function AnotherJSFunction{
...
}
});
</script>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex=0>
<asp:View ID="main" runat="server">
<div class=item>
<asp:TextBox ID="txtuser" runat="server" ></asp:TextBox><br />
...
这是文件后面的编辑代码(control.ascx.cs):
protected void Page_Load(object sender, System.EventArgs e)
{
DotNetNuke.Framework.jQuery.RequestUIRegistration();
}
这是 Web 处理程序以防万一(ashx):
<%@ WebHandler Language="C#" Class="Search_Username" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public class Search_Username : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Username from Users where Username like @SearchText + '%' and IsSuperUser <> 1";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
StringBuilder sb = new StringBuilder();
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(sdr["Username"]).Append(Environment.NewLine);
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
我已经测试了 Web 处理程序 Search_Username.ashx,它工作正常,但我不确定文件的链接是否正确。jQuery 自动完成仍然不起作用,也没有错误。我不知道在哪里解决,尽管我在这里查看了一些问题。有人能帮我吗?