AutoComplete control usage problem with VB.net, or is it only me?

Last post 11-23-2007 8:52 AM by moufis. 6 replies.

Sort Posts:

  • AutoComplete control usage problem with VB.net, or is it only me?

    01-31-2007, 8:20 PM
    • Member
      point Member
    • Whiteoak
    • Member since 02-01-2007, 12:45 AM
    • Posts 3

    I have a problem. It has to do with the AutoComplete control. Well first things first, i write in VB.net and suspect the problem may arrise from compatability with that.

    The thing is i can run sample applications with the toolkit, works fine. But when i want to put it to use, namely change code from C# to VB the film snaps, so to speak.

    Well some of the controls work, some don't or cause direct script errors. The control i am interested in (was actually going to build it when i saw the new release) is the AutoComplete control.

    I have been doing some with custom, user and rendered controls with .net in the past and am positively thrilled about the outlook, but it's gotta work. So here follow the details, i really hope i am doing something wrong, that it can work:

    Step one was to convert the web service associate with the example which was done by creating a new AJAX enabled website, then adding reference to the AjaxControlToolkit

    The service in VB.net looks like this (and works if navigating to it by the .asmx extention):

    '----File listing AutoComplete.vb : 

    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

    <WebMethod()> _

    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

    Dim Rnd As Random, items() As String, i As Integer, strTemp As String = ""

    If count = 0 Then count = 10

    If prefixText.Equals("xyz") Then

    Return New ArrayList(0).ToArray

    End If

    Rnd =

    New Random

    ReDim items(count)

    For i = 0 To count Step 1

    Dim c1 As Char = Chr(Rnd.Next(65, 90))

    Dim c2 As Char = Chr(Rnd.Next(97, 122))

    Dim c3 As Char = Chr(Rnd.Next(97, 122))

    strTemp = prefixText & c1 & c2 & c3

    items(i) = strTemp

    Next

    Return items

     

    End Function

    End

    Class

    '---- END of File listing AutoComplete.asmx.vb :

    So far so good. I was using a single page web application to test this, so i cleverly named the form just like in the sample, but omitted to use the master/ detail page structure.

    The page looks like this (and produces no result, no nice drop down div to be navigated into with arrow keys or anything, nothing happens when i run this:)

    '-------------File listing Default.aspx------------------

     

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <%@ Register

    Assembly="AjaxControlToolkit"

    Namespace="AjaxControlToolkit"

    TagPrefix="AJAX" %>

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <

    html xmlns="http://www.w3.org/1999/xhtml">

    <

    head runat="server">

    <title>Untitled Page</title>

    </

    head>

    <

    body>

    <form id="aspnetForm" name="aspnetForm" runat="server">

    <asp:ScriptManager runat="server" />

    <div class="demoarea">

    <div class="demoheading">AutoComplete Control lab</div>

    <p/>

     

    Type something

    &nbsp;:&nbsp;&nbsp;

    <asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />

    <AJAX:AutoCompleteExtender

    runat="server"

    ID="autoComplete1"

    TargetControlID="myTextBox"

    ServicePath="AutoComplete.asmx"

    ServiceMethod="GetCompletionList"

    MinimumPrefixLength="2"

    CompletionInterval="1000"

    EnableCaching="true"

    CompletionSetCount="12" />

    <script type="text/javascript">

    // Work around browser behavior of "auto-submitting" simple forms

    var frm = document.getElementById("aspnetForm");

    if (frm) {

    frm.onsubmit =

    function() { return false; };

    }

    </script>

    </div>

    </form>

    </

    body>

    </

    html>

    '-------------End of File listing Default.aspx------------------

    As you may notice it is a complete copy of the AjaxControlToolkit example, with the only difference that i have allowed myself to register the toolkit using the AJAX prefix instead of the longer ajaxToolkit tagprefix.

    Can you assist in this? I will be bouncing about in the lab cheering with spontaneus 'the wave's and crowd sounds in your general direction if you canGeeked

    Secondly, have you had a working version of the AutoComplete control running? ( that i might know the source of the error is touching my keys )

  • Re: Jep, was my mistake!

    02-03-2007, 9:19 AM
    Answer
    • Member
      point Member
    • Whiteoak
    • Member since 02-01-2007, 12:45 AM
    • Posts 3

    Heureka!

    Well it did seem too easy to blame the creators ;-)

    I was fortunate enough to find the error myself, hence will hereby share it. My fault was in total not to  add the associative scripting, like you can see below in red.

    Inherits System.Web.Services.WebService

    <WebMethod()> _

    <Script.Services.ScriptService()> _

    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

     

    Little in between me and google-suggest like interfaces! thx Microsoft

    Brilliant move with the AjaxControlToolkit, once we got those demo controls nailed down for details, system.web.extentions is ever so much more easy to approach, hardly have to SOAP anything manually or even touch the JavaScripts /\/\/\/  (<= MSwave)

    Cheers all,

    Whiteoak.

  • Re: Jep, was my mistake!

    02-05-2007, 6:43 AM
    • Member
      10 point Member
    • energia
    • Member since 02-05-2007, 11:37 AM
    • Posts 13

    I'm having some trouble getting the autocomplete to work, so I just copied your code too see where
    my problems might be. But (as I asume) you webservice function is placed in a code-behind file?

     Shouldn't the scriptmethod tag look like this then? 

    <Script.Services.ScriptMethod()> _

     

    Moste of the examples I have seen do not use the webservice code behind, instead using
    in-line coding of the asmx file, or place the function in the page where the control is located.

  • Re: Jep, was my mistake!

    02-05-2007, 6:55 AM
    • Member
      10 point Member
    • energia
    • Member since 02-05-2007, 11:37 AM
    • Posts 13

    Ok, well, I figured it out. As a help to others, here comes the answer

     

    <WebService(Namespace:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    <Script.Services.ScriptService()> _
    Public Class AutoComplete
    
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
    
     

     

    It should be a ScriptService tag, but it should be placed in the right section. Some examples show it like this,
    and it wont work:

    Inherits System.Web.Services.WebService
    <WebMethod()> _
    <Script.Services.ScriptMethod()> _
    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

  • Re: Jep, was my mistake!

    02-05-2007, 7:00 AM
    • Contributor
      2,460 point Contributor
    • Steve Marx
    • Member since 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643

    Your code looks right!  Just some extra info:

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: Jep, was my mistake!

    02-23-2007, 4:56 AM
    • Member
      23 point Member
    • Radoslav
    • Member since 02-20-2007, 6:10 PM
    • Posts 78
    Would you be so kind to attach the AutoComplete.vb file (or possibly together with the aspx and asmx pages) so we can download and test it? Thanks a lot!
  • Re: Jep, was my mistake!

    11-23-2007, 8:52 AM
    • Member
      8 point Member
    • moufis
    • Member since 01-03-2007, 4:56 AM
    • Posts 5

    Thank you Very much it was very helpfull

Page 1 of 1 (7 items)