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:
<%@ WebService Language ="Vb" Class="autocomplete" %>
Imports system.web.services
Imports System.collections
<Microsoft.Web.Script.Services.ScriptService()> _
Public Class autocomplete
Inherits System.Web.Services.WebService
Public Function autocomplete()
End Function
<WebMethod()> Public Function listnames(ByVal prefixtext1 As String, ByVal count As Integer) As String()
Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("Data Source=bmss;Initial Catalog=Users;User ID=sa")
Dim cmd As New System.Data.SqlClient.SqlCommand
Dim paramx As Data.SqlClient.SqlParameter
paramx = New Data.SqlClient.SqlParameter("@prefix", prefixtext1)
cmd.CommandText = "liststaff"
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Connection = sqlConnection1
cmd.Parameters.Add(paramx)
sqlConnection1.Open()
' Dim output(1000) As String
Dim matches As New System.Collections.Generic.List(Of String)
Dim i As Integer = 0
Dim reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
While reader.Read()
'output(i) = reader(0)
matches.Add(reader(0))
i = i + 1
End While
'Return output
Return matches.ToArray
sqlConnection1.Close()
End Function
End Class
Here is my stored procedure:
CREATE PROCEDURE [dbo].[liststaff]
@prefix nvarchar(100)
AS
select username from vstaff where username like @prefix +'%'
GO
"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.
Member
7 Points
46 Posts
autocompleteextender not popping up
May 10, 2007 06:42 AM|peterdungan|LINK
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:
Here is my stored procedure:
Here is my autocompleteextender:
Participant
1350 Points
395 Posts
Re: autocompleteextender not popping up
May 10, 2007 08:45 AM|Phanatic|LINK
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:
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
http://blogs.msdn.com/PhaniRaj
Member
7 Points
46 Posts
Re: autocompleteextender not popping up
May 10, 2007 09:10 AM|peterdungan|LINK
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?
Participant
1350 Points
395 Posts
Re: autocompleteextender not popping up
May 10, 2007 10:45 AM|Phanatic|LINK
Yeah, you will need to add the ScriptMethod Attribute to the webmethod .
[System.Web.Script.Services.ScriptMethod]
YourMethodName
http://blogs.msdn.com/PhaniRaj
Member
7 Points
46 Posts
Re: autocompleteextender not popping up
May 11, 2007 06:27 AM|peterdungan|LINK
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()Member
7 Points
46 Posts
Re: autocompleteextender not popping up
May 11, 2007 07:00 AM|peterdungan|LINK
Member
7 Points
46 Posts
Re: autocompleteextender not popping up
May 11, 2007 07:12 AM|peterdungan|LINK
Member
7 Points
46 Posts
Re: autocompleteextender not popping up
May 11, 2007 09:17 AM|peterdungan|LINK
Microsoft.Web.Script.Services.ScriptMethod
instead of
System.Web.Script.Services.ScriptMethod)
Thanks for your help