Hi Can anybody help us, why the below code is not working, when im entering some product name in the text box.. any help appreciated.. thanks
autocomplete.asmx
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
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
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 = System.Configuration.ConfigurationManager.ConnectionStrings("JC").ConnectionString
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 product Where Name 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("Name").ToString()
dbValues = dbValues.ToLower()
txtItems.Add(dbValues)
Next
Return txtItems.ToArray()
End Function
End Class
'''''''''''''''''''''''''''''
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="testingdel.aspx.vb" Inherits="Bestpaisa.testingdel" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="Autocomplete.css" rel="stylesheet" type="text/css" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div><asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Products/kids">sdfsdfsdf
HyperLink</asp:HyperLink>
<asp:TextBox ID="myTextBox" runat="server" autocomplete ="off"></asp:TextBox>
<asp:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
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 = '0px';
}" />
<%-- 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>
</div>
</form>
</body>
</html>
bsarahim
Member
14 Points
145 Posts
problem with the code
Dec 30, 2012 01:22 PM|LINK
Hi Can anybody help us, why the below code is not working, when im entering some product name in the text box.. any help appreciated.. thanks autocomplete.asmx 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 <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <System.Web.Script.Services.ScriptService()> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 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 = System.Configuration.ConfigurationManager.ConnectionStrings("JC").ConnectionString 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 product Where Name 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("Name").ToString() dbValues = dbValues.ToLower() txtItems.Add(dbValues) Next Return txtItems.ToArray() End Function End Class ''''''''''''''''''''''''''''' <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="testingdel.aspx.vb" Inherits="Bestpaisa.testingdel" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <link href="Autocomplete.css" rel="stylesheet" type="text/css" /> <title></title> </head> <body> <form id="form1" runat="server"> <div><asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Products/kids">sdfsdfsdf HyperLink</asp:HyperLink> <asp:TextBox ID="myTextBox" runat="server" autocomplete ="off"></asp:TextBox> <asp:AutoCompleteExtender ID="autoComplete1" runat="server" EnableCaching="true" BehaviorID="AutoCompleteEx" MinimumPrefixLength="2" TargetControlID="myTextBox" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" CompletionInterval="1000" CompletionSetCount="20" 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 = '0px'; }" /> <%-- 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> </div> </form> </body> </html>majd_wadi
Member
513 Points
225 Posts
Re: problem with the code
Dec 30, 2012 04:06 PM|LINK
What exactly are you trying to do ? fill the textbox with autocomplete values ?
~Please mark as answer if this helps u~
bsarahim
Member
14 Points
145 Posts
Re: problem with the code
Dec 31, 2012 03:44 AM|LINK
yes
bsarahim
Member
14 Points
145 Posts
Re: problem with the code
Dec 31, 2012 01:32 PM|LINK
Any help appreciated..thanks
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: problem with the code
Jan 01, 2013 08:49 AM|LINK
Refer this
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx and http://www.asp.net/ajaxlibrary/act_AutoComplete.ashx
Please refer to the example at: http://forums.asp.net/p/1582937/3996380.aspx#3996380.
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Yanping Wang...
Star
14919 Points
1537 Posts
Microsoft
Re: problem with the code
Jan 04, 2013 06:31 AM|LINK
Hi bsarahim,
thanks for your post.
to dig the issue in your markup, you can start with creating a simple AutoComplete example, you can refer: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
and then debug the ashx code and check if it return the expected result.
a simple sample you can also refer: http://dotnetslackers.com/Community/blogs/kaushalparik/archive/2008/06/06/autocomplete-textbox-using-ajax-autocompleteextender-from-database.aspx
Please let me know how it goes, thanks.
Feedback to us
Develop and promote your apps in Windows Store