I am using the AutoComplete control and I am seeing a weird behavior. The data for the AutoComplete is populated from the database using a LIKE statement. Here's my problem:
* I have 2 values in my table starting with "the": "the cat" and "the dog"
* I enter "the" in my input box. As expected, the dropdown is populated with "the dog" and "the cat"
* I do not choose either value. My input box is only populated with "the".
* I wait for a couple of seconds and I type again "the". My input box contains "the the" and the dropdown is populated with "the the dog" and "the the cat" (the table does not contain these values)
As I can see from the SQL trace, the parameter sent to the database is "the" even though my input box contain "the the". What is sent is what I added, not the whole text contained in the input box.
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetCompletionListWithContextAndValues(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
Dim Utils As utils
Utils = New utils()
Dim items As System.Collections.Generic.List(Of String)
items = New System.Collections.Generic.List(Of String)
Dim items2 As ListItemCollection
items2 = Utils.getOrganizationByOrganizationName(prefixText)
Dim xListItem As ListItem
For Each xListItem In items2
items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(xListItem.Text, xListItem.Value))
Next
Return items.ToArray()
End Function
The getOrganizationByOrganizationName function:
Public Function getOrganizationByOrganizationName(ByVal OrganizationName As String) As ListItemCollection
' declares connection objects Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader Dim SqlConnection As System.Data.SqlClient.SqlConnection SqlConnection = New System.Data.SqlClient.SqlConnection SqlConnection.ConnectionString = CType(configurationAppSettings.GetValue("SqlConnection.ConnectionString", GetType(System.String)), String) Dim items As ListItemCollection items = New ListItemCollection
Dim getUserMenu As System.Data.SqlClient.SqlCommand getUserMenu = New System.Data.SqlClient.SqlCommand
Dim dreader As SqlClient.SqlDataReader SqlConnection.Open() getUserMenu.Parameters("@OrganizationName").Value = OrganizationName dreader = getUserMenu.ExecuteReader(CommandBehavior.Default) While dreader.Read() items.Add(New ListItem(dreader("OrganizationName").ToString(), dreader("OrganizationID").ToString())) End While dreader.Close() SqlConnection.Close()
ALTER PROCEDURE [dbo].[getOrganizationByOrganizationName]
(
@OrganizationName varchar(50)
)
AS
SET NOCOUNT ON;
SELECT top 20
Organization.OrganizationID,
Organization.OrganizationName
FROM Organization
WHERE
OrganizationActive = 1 AND
OrganizationName Like @OrganizationName + '%'
dreamer76
Member
4 Points
10 Posts
Weird behavior with AutoComplete
Dec 31, 2007 05:56 AM|LINK
I am using the AutoComplete control and I am seeing a weird behavior. The data for the AutoComplete is populated from the database using a LIKE statement. Here's my problem:
* I have 2 values in my table starting with "the": "the cat" and "the dog"
* I enter "the" in my input box. As expected, the dropdown is populated with "the dog" and "the cat"
* I do not choose either value. My input box is only populated with "the".
* I wait for a couple of seconds and I type again "the". My input box contains "the the" and the dropdown is populated with "the the dog" and "the the cat" (the table does not contain these values)
As I can see from the SQL trace, the parameter sent to the database is "the" even though my input box contain "the the". What is sent is what I added, not the whole text contained in the input box.
Is that normal? How can this behavior be changed?
Thanks a lot.
autocomplete
impathan
Contributor
4371 Points
837 Posts
Re: Weird behavior with AutoComplete
Dec 31, 2007 10:18 AM|LINK
Post your web method code
ImranKhan pathan
dreamer76
Member
4 Points
10 Posts
Re: Weird behavior with AutoComplete
Dec 31, 2007 02:52 PM|LINK
Here's the VB Code:
<System.Web.Services.WebMethod()> _ <System.Web.Script.Services.ScriptMethod()> _ Public Shared Function GetCompletionListWithContextAndValues(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String() Dim Utils As utils Utils = New utils() Dim items As System.Collections.Generic.List(Of String) items = New System.Collections.Generic.List(Of String) Dim items2 As ListItemCollection items2 = Utils.getOrganizationByOrganizationName(prefixText) Dim xListItem As ListItem For Each xListItem In items2 items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(xListItem.Text, xListItem.Value)) Next Return items.ToArray() End FunctionThe getOrganizationByOrganizationName function:
The autoComplete code:
Thanks!
dreamer76
Member
4 Points
10 Posts
Re: Weird behavior with AutoComplete
Jan 01, 2008 05:52 PM|LINK
kavyamark
Member
6 Points
20 Posts
Re: Weird behavior with AutoComplete
Aug 26, 2009 05:47 PM|LINK
Hello dreamer76
I know its been long time you might have forgotten about this issue
But can you let me know how exactly you resolved the issue.
Even i am having the same issue.i changed delimitercharacters in so many different ways but no luck.please do let me know
Thanks