我们有一个ASP网站,它具有文本框的自动完成功能。当我们在本地测试时,该功能能够工作。在我们在实时服务器上托管网站后,我们发现自动完成功能不再起作用。我们还需要使该功能在实时服务器上运行。我们使用Visual Studio工具开发网站。但是,我们的实时服务器没有Visual Studio。我们在服务器上使用IIS 8托管了该网站。我们在这个问题上需要帮助。
以下是代码的详细信息。
我们在App_Code文件夹中创建了一个名为AutoComplete.vb的类。以下是编码。
AutoComplete.vb
Imports System
Imports System.Collections
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX,
' uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class AutoComplete
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable
<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, _
ByVal count As Integer) As String()
'ADO.Net
Dim strCn As String = _
"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\MSDRepairWebDB\App_Data\Errorcode.mdf;Integrated Security=True;User Instance=True"
cn.ConnectionString = strCn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = cn
cmd.CommandType = CommandType.Text
'Compare String From Textbox(prefixText)
'AND String From Column in DataBase(CompanyName)
'If String from DataBase is equal to String from TextBox(prefixText)
'then add it to return ItemList
'-----I defined a parameter instead of passing value
'directly to prevent SQL injection--------'
cmd.CommandText = "select * from Errorcode Where Test like @myParameter"
cmd.Parameters.AddWithValue("@myParameter", prefixText + "%")
Try
cn.Open()
cmd.ExecuteNonQuery()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
Catch ex As Exception
Finally
cn.Close()
End Try
dt = ds.Tables(0)
'Then return List of string(txtItems) as result
Dim txtItems As New List(Of String)
Dim dbValues As String
For Each row As DataRow In dt.Rows
''String From DataBase(dbValues)
dbValues = row("Test").ToString()
dbValues = dbValues.ToLower()
txtItems.Add(dbValues)
Next
Return txtItems.ToArray()
End Function
End Class
这是我们创建的Web服务的编码
AutoComplete.asmx
`<%@ WebService Language="vb" CodeBehind="F:\MSDRepairWebDB\App_Data\Errorcode.mdf" Class="AutoComplete" %`>
这是使用自动填充文本框的实际页面的代码 的 SearchErrorCode.aspx
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPage.Master" CodeBehind="SearchErrorCode.aspx.vb" Inherits="MSDRepairWebDB.SearchErrorCode" EnableEventValidation="false" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<h2>
Search Error Code</h2>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="AutoComplete.asmx"/>
</Services>
</asp:ToolkitScriptManager>
<asp:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="1"
TargetControlID="tbDGNTestingErrorCode"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="0"
CompletionSetCount="10"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
<Animations>
<OnShow>
<Sequence>
<%-- Make the completion list transparent and then show it --%>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%>
<ScriptAction Script="// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '12px';
}" />
<%-- Expand from 0px to the appropriate size while fading in --%>
<Parallel Duration=".4">
<FadeIn />
<Length PropertyKey="height" StartValue="0"
EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript=
"$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</asp:AutoCompleteExtender>
<tr align=left>
<th class="style2" >
Error Code
</th>
<td>
<asp:TextBox ID="tbDGNTestingErrorCode" autocomplete ="off" runat="server"
Width="190px" MaxLength="5" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbDGNTestingErrorCode"
ErrorMessage="Error Code Required!" InitialValue=""
ForeColor="#FF3300"></asp:RequiredFieldValidator>
</td>
</tr>
</asp:Content>
这是数据库表结构。
数据库:Errorcode.mdf
表:错误代码
有人可以帮我建议在实时服务器上自动完成工作吗?
由于