locked
autocompleteextender not popping up RRS feed

  • Question

  • User1337378173 posted

    Hi.

    I have set up an autocompletextender that should show a list of names from a db based on the text entered in a textbox.

    It doesn't work. No error appears to be generated, and when I try running the stored procedure with the same text via a button it seems to work fine. But the autocomplete panel doesn't popup.

    Can anyone see what is wrong? Any help appreciated.

    Thanks

     

    Here is my webservice: 

      

    1    <%@ WebService Language ="Vb" Class="autocomplete" %>
    2    Imports system.web.services
    3    
    4    Imports System.collections
    5    
    6    <Microsoft.Web.Script.Services.ScriptService()> _
    7     Public Class autocomplete
    8        Inherits System.Web.Services.WebService
    9    
    10       Public Function autocomplete()
    11           
    12       End Function
    13       <WebMethod()> Public Function listnames(ByVal prefixtext1 As String, ByVal count As Integer) As String()
    14           Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=bmss;Initial Catalog=Users;User ID=sa")
    15           Dim cmd As New System.Data.SqlClient.SqlCommand
    16           Dim paramx As Data.SqlClient.SqlParameter
    17           
    18           
    19           paramx = New Data.SqlClient.SqlParameter("@prefix", prefixtext1)
    20      
    21           
    22           cmd.CommandText = "liststaff"
    23           cmd.CommandType = Data.CommandType.StoredProcedure
    24           cmd.Connection = sqlConnection1
    25           cmd.Parameters.Add(paramx)
    26         
    27           sqlConnection1.Open()
    28           ' Dim output(1000) As String
    29           Dim matches As New System.Collections.Generic.List(Of String)
    30           Dim i As Integer = 0
    31           Dim reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
    32           While reader.Read()
    33               'output(i) = reader(0)
    34               matches.Add(reader(0))
    35               i = i + 1
    36           End While
    37       
    38           'Return output
    39           Return matches.ToArray
    40           
    41           sqlConnection1.Close()
    42       End Function
    43   
    44   End Class
    45   
    

     Here is my stored procedure:

      

    1    CREATE PROCEDURE [dbo].[liststaff]
    2    @prefix nvarchar(100)
    3     AS
    4    select username from vstaff where username like @prefix +'%'
    5    GO
    6    
    

     

     

    Here is my autocompleteextender:

     

    cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="acetextbox" ServiceMethod="listnames" 
    ServicePath="autocomplete.asmx" CompletionSetCount="4">
    <asp:TextBox ID="acetextbox" runat="server"></asp:TextBox
     
    Thursday, May 10, 2007 6:42 AM

Answers

  • User-1500755525 posted

    Hi,

    Please change the Name of the parameters to be :

    ByVal prefixtext1  to ByVal prefixText.

    The Documentation mentions this..

     

    "ServiceMethod - The web service method to be called. The signature of this method must match the following:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetCompletionList(string prefixText, int count) { ... }

    Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case. "

    The reason the parameter names must be hard-coded is that the AutoCompleteExtender has the WebService Call hardcoded in this line.

    "

    Sys.Net.WebServiceProxy.invoke(this.get_servicePath(), this.get_serviceMethod(), false,

    { prefixText : this._currentPrefix, count: this._completionSetCount },

    Function.createDelegate(this, this._onMethodComplete),

    Function.createDelegate(this, this._onMethodFailed),

    text);"

     

    Hope this helps.

    Mark my reply as the answer if it resolves your problem

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 10, 2007 8:45 AM

All replies

  • User-1500755525 posted

    Hi,

    Please change the Name of the parameters to be :

    ByVal prefixtext1  to ByVal prefixText.

    The Documentation mentions this..

     

    "ServiceMethod - The web service method to be called. The signature of this method must match the following:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetCompletionList(string prefixText, int count) { ... }

    Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case. "

    The reason the parameter names must be hard-coded is that the AutoCompleteExtender has the WebService Call hardcoded in this line.

    "

    Sys.Net.WebServiceProxy.invoke(this.get_servicePath(), this.get_serviceMethod(), false,

    { prefixText : this._currentPrefix, count: this._completionSetCount },

    Function.createDelegate(this, this._onMethodComplete),

    Function.createDelegate(this, this._onMethodFailed),

    text);"

     

    Hope this helps.

    Mark my reply as the answer if it resolves your problem

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 10, 2007 8:45 AM
  • User1337378173 posted

    Thanks, I changed this. Now it is:

    <WebMethod()> Public Function listnames(ByVal prefixText As String, ByVal count As Integer) As String()

    but the popup is still not appearing. Do you have any other suggestions?

    Thursday, May 10, 2007 9:10 AM
  • User-1500755525 posted

    Yeah, you will need to add the ScriptMethod Attribute to the webmethod .

     [System.Web.Script.Services.ScriptMethod]

    YourMethodName

    Thursday, May 10, 2007 10:45 AM
  • User1337378173 posted

    When I try that I get an error saying 'System.Web.Script.Services.ScriptMethod' is not defined

    I might have the syntax wrong, although I've tried altering it a few times. I'm using vb.

     

    <WebMethod()> _

    <System.Web.Script.Services.ScriptMethod()> _

    Public Function listnames(ByVal prefixText As String, ByVal count As Integer) As String()

     

    Friday, May 11, 2007 6:27 AM
  • User1337378173 posted
    I think I'm missing the system.web.extensions dll
    Friday, May 11, 2007 7:00 AM
  • User1337378173 posted
    Yes I am. An older version of the ajax extensions seems to be installed on the server.
    Friday, May 11, 2007 7:12 AM
  • User1337378173 posted
    (so it worked when I referenced

    Microsoft.Web.Script.Services.ScriptMethod

     instead of

    System.Web.Script.Services.ScriptMethod)

     Thanks for your help

    Friday, May 11, 2007 9:17 AM