Showing posts with label autocomplete. Show all posts
Showing posts with label autocomplete. Show all posts

Saturday, March 24, 2012

Problem getting AutoComplete Extender to work

Hi I just want to get the autocomplete extender to work with a text box and I'm having trouble getting it to work. It seems like the service isnt being called or that the control isnt working. Compiles fine and no errors in IE when its opened

Heres the code.

AJAXServices.asmx

<%@dotnet.itags.org. WebService Language="VB" CodeBehind="~/App_Code/AjaxServices.vb" Class="AjaxServices" %>

AJAXServices.vb

Imports DataAccess
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
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 AjaxServices
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetModelList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim strSQL As String
Dim titleArList As New List(Of String)
Dim dtModels As DataTable

strSQL = "SELECT DISTINCT Alias FROM LaptopDescTier WHERE Alias LIKE @dotnet.itags.org.Model"
strSQL = strSQL.Replace("@dotnet.itags.org.Model", FormatSQLInfo(prefixText & "%"))
dtModels = ReturnTable(strSQL)

For Each drModel As DataRow In dtModels.Rows
titleArList.Add(drModel("Alias").ToString)
Next

Return titleArList.ToArray()

End Function

End Class

UpdateLaptopModels.aspx

<%@dotnet.itags.org. Page AutoEventWireup="false" CodeFile="UpdateLaptopModels.aspx.vb" Inherits="UpdateLaptopModels"
Language="VB" MaintainScrollPositionOnPostback="true" MasterPageFile="~/Admin.master"
Title=":: Laptop Management System ~ Administration ::" %
<asp:Content ID="Content1" runat="Server" ContentPlaceHolderID="cphAdmin">
<asp:ScriptManager ID="ScriptManager" runat="server">
</asp:ScriptManager>
<div class="Container">
<h2>
Update Laptops Models</h2>
<div class="StandardBreakSpace">
</div>
<asp:TextBox ID="txtAlias" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceAlias" runat="server" CompletionInterval="1000"
CompletionSetCount="12" EnableCaching="true" MinimumPrefixLength="1" ServiceMethod="GetModelList" Enabled="true"
ServicePath="Services/AjaxServices.asmx" TargetControlID="txtAlias">
</ajaxToolkit:AutoCompleteExtender>
</div>
</asp:Content>

Web.config

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>

</appSettings>
<connectionStrings>

</connectionStrings>
<system.web>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
</pages>
<identity impersonate="true"/>
<authentication mode="Windows"/>
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<profile>
<properties>
<add name="SearchTerms" type="System.Collections.Specialized.StringCollection" serializeAs="Xml"/>
</properties>
</profile>
</system.web>
<system.web.extensions>
<scripting>
<webServices>

<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
</configuration


Once I get this working I want to use the text box and extender in a itemtemplate in a gridview. Will that work?

Thanks for looking into this and all suggestions are welcome!

Dude, found it!!!

change this...


<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class

TO

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class


I'll give this a try at work tomorrow. I just gave up. If this works, you are truly the man!Wink



If not, you can try this:

http://forums.asp.net/thread/1563579.aspx

I had trouble getting autocomplete in vb to work, and listed a few things I noticed there.

(Using in-page methods, no .asmx)


Jared,

Unfortunately even this doesnt get it to fire. I wonder if you could put together a quick sample that fires in VB to use as a template.


I posted my working code (simplified) on the thread i linked above...

FYI - I've been banging my head all day, and this worked for me. Is there something to be done to get around the need to remember to make this change? This was a pre-exising ASP.NET app to which I'm adding AJAX functionality.

Thanks!

rojay12:

Dude, found it!!!

change this...


<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class

TO

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class

Problem in AJAX Autocomplete

Hi i am using Autocompletion feature in my project for loading cities with matched keys in textbox using AutoCompleteExtender of Ajax Toolkit. Its working fine but when i use the same code in User control (.ascx) file, then i can't work. and also when i use the same code for autocompletion in URL Friendly Urls then the page hang out can any one told me why this happen and how i use AutoCompleteExtender efficiently in my project. My complete coding is shown below.

.aspx page.

<asp:TextBox ID="txt_search_city" Width="130px" runat="server">

<cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" TargetControlID="txt_search_city"
ServiceMethod="GetCompletionListWithContext" UseContextKey="true" MinimumPrefixLength="2"
EnableCaching="false" CompletionSetCount="20" CompletionInterval="2000" FirstRowSelected="true"
DelimiterCharacters=";," />

Code behind Section:

<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetCompletionListWithContext(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
If Not contextKey = Nothing Then
Return "this is a total of fifteen words that will be returned when we use context".Split(" ")
End If
If count = 0 Then
count = 20
End If
Dim items As New System.Collections.Generic.List(Of String)
'get data from database
Dim _loc As New Locations
Dim str As String
Dim ds As DataSet = _loc.Load_Cities(prefixText, count)
If ds.Tables(0).Rows.Count > 0 Then
Dim i As Integer
For i = 0 To count - 1
str = ds.Tables(0).Rows(i).Item("city").ToString()
If ds.Tables(0).Rows(i).Item("StateProvince").ToString() = "Rentals" Then
str = ds.Tables(0).Rows(i).Item("city").ToString() & " - " & ds.Tables(0).Rows(i).Item("CountryCode").ToString()
Else
str = ds.Tables(0).Rows(i).Item("city").ToString() & " - " & ds.Tables(0).Rows(i).Item("StateProvince").ToString()
End If
items.Add(str)
Next
End If
Return items.ToArray()
End Function

Waiting for some helpful response.

Thanks.

You may need a ScriptManager or a ScriptManagerProxy control in the user control.


Hi thanks for your reply...

I have already place Script manager on page rather than user control. is it not ok, and also when i am using auto complete on User Friendly URL Like http://www.abc.com/categories/232/auto.aspx then complete page is hang out. what will be the possible cause here for autocomplete control.

Thanks.


media_1408:

when i use the same code in User control (.ascx) file, then i can't work.

The code in a user control can't be accessed from client side directly, that's because request for file extension .ascx is blocked.

media_1408:

also when i use the same code for autocompletion in URL Friendly Urls then the page hang out

The ajax extension uses the virtualPath of current page to get an instance of the corresponding object and invoke a method on it with Reflection, and it's likely to fail to work when url rewriting is enabled. Since the a file can't be found with the user friendly URL.

In my opinion, a better idea is to use Web Service rather than a Page Method. And don't apply any rewriting rules to .asmx file extension.


Thanks a lot for your wonderful help, as user control problem is not solved and also it is not big issue, but by using Web Service rather than a Page Method, page hanging problem due to auto completion is also solved on URL Friendly Urls.


Thanks.