0

We have an ASP website that has the auto complete function for textbox. When we test on local, the function able to work. After we host the website on live server, we found that the auto complete function is not working anymore. We need to make that function works on the live server as well. We develop the website using Visual Studio tool. However, our live server did not have Visual Studio. We hosted the website using IIS 8 on the server. We need help on this issue.

Below are the details of codes.

We created a class called AutoComplete.vb in the App_Code folder. Below are the coding.

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

This the coding for the web service we created

AutoComplete.asmx

`<%@ WebService Language="vb" CodeBehind="F:\MSDRepairWebDB\App_Data\Errorcode.mdf" Class="AutoComplete" %`>

This is the code for the actual page that using the autocomplete textbox 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&nbsp;&nbsp;
    </th>
    <td>
    &nbsp;<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>

This is the database table structure.

Database : Errorcode.mdf

Table : Errorcode

Errorcode table

Can anyone help me to advise to make the auto complete work on the live server?

Thanks

Mohamad Arafat
  • 573
  • 1
  • 5
  • 24

0 Answers0