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

No comments:

Post a Comment