Finally I got this to work with VB -
My first step was to get the example ajax application working: http://ajax.asp.net/default.aspx?tabid=47&subtabid=471
Of course there is no VB example - So I converted the C example to VB - which was pretty easy since I only needed the autocomplete and none of the other examples.
The only way I could get the autocomplete to work was to have the webservice written in C instead of VB. Everything I checked shows the VB and C# web services as identical.
So... does autocomplete not work with VB webservices?
This works for me
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Autocomplete
Inherits System.Web.Services.WebService
Private Shared autoCompleteWordList As String()
<WebMethod()> _
Public Function GetWordList(ByVal prefixText As String, ByVal count As Integer) As String()
If (autoCompleteWordList Is Nothing) Then
Dim temp() As String = IO.File.ReadAllLines(Server.MapPath("~/App_Data/words.txt"))
Array.Sort(temp, New CaseInsensitiveComparer)
autoCompleteWordList = temp
End If
Dim index As Integer = Array.BinarySearch(autoCompleteWordList, prefixText, New CaseInsensitiveComparer)
If (index < 0) Then
index = Not index
End If
Dim matchingCount As Integer
matchingCount = 0
Do While ((matchingCount < count) _
AndAlso (index _
+ (matchingCount < autoCompleteWordList.Length)))
If Not autoCompleteWordList((index + matchingCount)).StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) Then
'TODO: Warning!!! break;If
End If
matchingCount = (matchingCount + 1)
Loop
Dim returnValue() As String = New String((matchingCount) - 1) {}
If (matchingCount > 0) Then
Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount)
End If
Return returnValue
End Function
End Class
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server">
</atlas:ScriptManager>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server" Width="1010px"></asp:TextBox>
<atlas:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server">
<atlas:AutoCompleteProperties TargetControlID="TextBox1" Enabled="True" ServicePath="AutoComplete.asmx"
ServiceMethod="GetWordList" MinimumPrefixLength="1" />
</atlas:AutoCompleteExtender>
</div>
</form>
I am using your code to solve a problem that I am having.
I need modify it a bit to work with a database.
Can you help me out with this?
Thanks
Im trying this method the vb is good. i downloada words.txt that help.
but i try to run it on my website and is not working other ajax enable work like the passwordstrengt.
I presume you can do the lookup straight from SQL server rather than use a web service?
Did you get any replies as this is exactly what I would like to do.
cheers
Mike
Hi,
i install the AjaxControlToolkit, but AutoComplete doesn't want to work.
I search the web and find samples with the microsoft atlas dll.
I managed to use this dll and AutoComplete works fine.
Microsoft.web.atlas.dll and AjaxControlToolkit.dll seem not to work on the same page.
How can I solve my problem (make work AutoComplete Control) only using AjaxControlToolkit.dll.
Here, you can download my simple code to test: http://promesses.planet-work.com/fic/ajax.zip
Thank for your help
Here is some code that I wrote up to work with a database. It's in VB.NET for all those VB heads out there. Hopefully this will help all of you.
<%@.WebServiceLanguage="VB"Class="PartnerList" %>
Imports
System.WebImports
System.Web.ServicesImports
System.Web.Services.ProtocolsImports
System.Collections.GenericImports
System.DataImports
System.Data.SqlClientImports
System.Configuration<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:=
"http://www.commpartners.us/webservices", Description:="Webservice to allow a autocompleter service lookup")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public
Class PartnerListInherits System.Web.Services.WebService
<WebMethod(Description:=
"Method to retrieve Partner List")> _PublicFunction GetPartnerList(ByVal prefixTextAsString,ByVal countAsInteger)As ArrayDim SqlConnection1AsNew SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))Dim SqlCommand1AsNew SqlCommand("SELECT DISTINCT TOP(@.nrows) (COMP + ':' + NAME) As PartnerName From dbo.WhiteList WHERE Name Like @.term", SqlConnection1)
SqlCommand1.Parameters.AddWithValue(
"nrows", count)SqlCommand1.Parameters.AddWithValue(
"term", prefixText &"%")Dim suggestionsAsNew List(OfString)SqlConnection1.Open()
Dim drAs SqlDataReader = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)While dr.Read
suggestions.Add(dr(0).ToString)
EndWhileReturn suggestions.ToArray
EndFunction
End
ClassAnd for the front facing code:<asp:TextBoxID="SearchPartner"runat="server"Width="216px"></asp:TextBox>
<asp:ButtonID="FindBtn"runat="server"OnClick="FindPartner"Text="Find"/>
<ajaxToolkit:AutoCompleteExtenderID="AutoCompleteSearch"MinimumPrefixLength="1"CompletionInterval="300"CompletionSetCount="10"runat="server"TargetControlID="SearchPartner" ServicePath="PartnerList.asmx"ServiceMethod="GetPartnerList"/
Also if you are wondering why my SQL query has (COMP + ':' + NAME) it's so I can show both an ID and concat it with the Company Name.
Have fun with the code and let me know if you have any problems.
JoeWeb
Nobody can help me ?
HI,
Sorry for my loging to our discussion , but i face the same problem with the autocompleteExtender that does not work with my VB.net project where the all other Controltookit work fine,..
i do the same steps which u wrote here but until know nothing happend and none of my code execute ,..........
JoeWeb:
Here is some code that I wrote up to work with a database. It's in VB.NET for all those VB heads out there. Hopefully this will help all of you.
<%@.WebServiceLanguage="VB"Class="PartnerList" %>
Imports
System.WebImports
System.Web.ServicesImports
System.Web.Services.ProtocolsImports
System.Collections.GenericImports
System.DataImports
System.Data.SqlClientImports
System.Configuration<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:=
"http://www.commpartners.us/webservices", Description:="Webservice to allow a autocompleter service lookup")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public
Class PartnerListInherits System.Web.Services.WebService
<WebMethod(Description:=
"Method to retrieve Partner List")> _PublicFunction GetPartnerList(ByVal prefixTextAsString,ByVal countAsInteger)As ArrayDim SqlConnection1AsNew SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))Dim SqlCommand1AsNew SqlCommand("SELECT DISTINCT TOP(@.nrows) (COMP + ':' + NAME) As PartnerName From dbo.WhiteList WHERE Name Like @.term", SqlConnection1)
SqlCommand1.Parameters.AddWithValue(
"nrows", count)SqlCommand1.Parameters.AddWithValue(
"term", prefixText &"%")Dim suggestionsAsNew List(OfString)SqlConnection1.Open()
Dim drAs SqlDataReader = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)While dr.Read
suggestions.Add(dr(0).ToString)
EndWhileReturn suggestions.ToArray
EndFunction
End
ClassAnd for the front facing code:<asp:TextBoxID="SearchPartner"runat="server"Width="216px"></asp:TextBox>
<asp:ButtonID="FindBtn"runat="server"OnClick="FindPartner"Text="Find"/>
<ajaxToolkit:AutoCompleteExtenderID="AutoCompleteSearch"MinimumPrefixLength="1"CompletionInterval="300"CompletionSetCount="10"runat="server"TargetControlID="SearchPartner" ServicePath="PartnerList.asmx"ServiceMethod="GetPartnerList"/
Also if you are wondering why my SQL query has (COMP + ':' + NAME) it's so I can show both an ID and concat it with the Company Name.
Have fun with the code and let me know if you have any problems.
JoeWeb
Did any of you read my post? This code works and I have tested it... COPY and Paste it and let me know how that works!
JoeWeb
DearJoeWeb
we do what exactly u do in the examle above , but nothing happened,..... so what is your suggession
DearJoeWeb
we do what exactly u do in the examle above , but nothing happened,..... so what is your suggession
I ame having the same problem where the autocomplete is not working.
When I try and run the code locally, which is running IE 6, I get a javascript error 'Sys.Debug is null or not an object', but I do not get a notification when running the page remotly on IE7.
The webservice is working when I go to the .asmx page locally.
Am I missing something? Do I need to register the web service somewhere?Help!!!
hi all
I had the same problem with the posted code how ever have solved it. You basically need to add the following to the page:
<asp:ScriptManager ID="ScriptManager1" runat="server" > <Services> <asp:ServiceReference Path="AutoComplete.asmx" /> </Services> </asp:ScriptManager>
I also changed the SqlConnection slightly as the method in the code above did not work:
Dim SqlConnection1As SqlConnection =New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("BVDB").ConnectionString)
hope this helps...
For me it works fine with MSSQL for tags. So I work with splitting Text by the last comma, if you do not need this, simply amend the code.
on aspx I have Script manager and
asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<
asp:TextBoxID="test1"runat="server"></asp:TextBox><
cc1:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"TargetControlID="test1"ServiceMethod="GetTags"ServicePath="UsedTags.asmx"MinimumPrefixLength="2"CompletionInterval="1000"EnableCaching="true"CompletionSetCount="12">
then UsedTags.asmx looks like
<%
@.WebServiceLanguage="VB"CodeBehind="~/App_Code/UsedTags.vb"Class="UsedTags" %>then App_Code/UsedTags.vb looks like
Option Explicit On
Option Strict On
Option Compare Binary
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class UsedTags
Inherits System.Web.Services.WebService
Private Shared autoCompleteWordList As String()
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Function GetTags(ByVal prefixText As String, ByVal count As Integer) As String()
Dim LastWord As String, _
ExpressionStart As String
If prefixText.Contains(",") AndAlso prefixText.LastIndexOf(",") < prefixText.Length Then
LastWord = prefixText.Substring(prefixText.LastIndexOf(",") + 1)
ExpressionStart = prefixText.Substring(0, prefixText.LastIndexOf(",") + 1)
Else
LastWord = prefixText
ExpressionStart = String.Empty
End If
Dim suggestions As New List(Of String)
If LastWord.Length > 0 Then
Dim connectionString As String
Using mySqlDbConnection As New SqlClient.SqlConnection()
connectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim mySqlDbCommand As New SqlClient.SqlCommand()
mySqlDbConnection.ConnectionString = connectionString
mySqlDbCommand.Connection = mySqlDbConnection
mySqlDbCommand.CommandType = CommandType.Text
mySqlDbCommand.CommandTimeout = 60
mySqlDbConnection.Open()
mySqlDbCommand.CommandText = "SELECT DISTINCT TOP(@.nrows) myTag FROM dbo.Tags WHERE myTag LIKE @.term ORDER BY myTag"
mySqlDbCommand.Parameters.AddWithValue("nrows", count)
mySqlDbCommand.Parameters.AddWithValue("term", LastWord & "%")
Dim ReaderData As SqlClient.SqlDataReader
ReaderData = mySqlDbCommand.ExecuteReader()
Do While ReaderData.Read
suggestions.Add(ExpressionStart & ReaderData(0).ToString)
Loop
ReaderData.Close()
mySqlDbConnection.Close()
End Using
End If
Return suggestions.ToArray
End Function
End Class
No comments:
Post a Comment