0

Here is code:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true" 
    AsyncPostBackTimeout="1000" ScriptMode="Release" 
    EnablePartialRendering="true" >
    <Services>
    <asp:ServiceReference Path ="~/FolderForService/Service.asmx" />
    </Services>



    <Scripts>
        <asp:ScriptReference Path="~/jscript/common.js" />
    </Scripts>       
</asp:ScriptManager>

<asp:UpdatePanel ID="upFSK" runat ="server" UpdateMode ="Conditional" >
 <ContentTemplate>

 <asp:Panel ID="Panel1" runat="server" >
 <asp:TextBox ID="TextBox1" runat="server" Visible="True" Width="128px"></asp:TextBox>
 <cc1:AutoCompleteExtender ID="ACE" 
      runat="server" 
      ServicePath="~/FolderForService/Service.asmx"
      ServiceMethod="WebMethod" 
      MinimumPrefixLength="4" 
      CompletionSetCount = "10"
      TargetControlID="TextBox1">                        
</cc1:AutoCompleteExtender>
</Panel>
 </ContentTemplate>
 </UpdatePanel>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Linq
Imports System.Web.Caching
Imports System.Data
Imports System.Collections.Generic
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
   Inherits System.Web.Services.WebService

'Web method which doesn't fire
<WebMethod()> _
Public Shared Function WebMethod(ByVal prefixTekst As String, ByVal count As Integer)   As List(Of String)
    ' Code  
End Function
End Class

What I did:

  1. I moved textbox outside Update Panel - 0 points
  2. Changed WebMethod from shared to instance - 0 points
  3. Moved WebService to root - 0 points
  4. Added PostBack=true and Triggers to UpdatePanel with textbox as a trigger - 0 points
  5. Created new WebSite with AutoComplete TextBox and without UpdatePanel - 10 points

What did I miss?

Willow
  • 59
  • 1
  • 9

2 Answers2

0

I've only done this in c#, I can give you a c# example if you request it otherwise check out this resource, it should help you get this operational. http://www.aspsnippets.com/Articles/ASP.Net-AJAX-Control-Toolkit-AutoCompleteExtender-without-using-Web-Services.aspx

From the link:

ASP:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>

<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
    MinimumPrefixLength="2"
    CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
    TargetControlID="txtContactsSearch"
    ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>

VB:

<System.Web.Script.Services.ScriptMethod(), _
System.Web.Services.WebMethod()> _
Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager _
         .ConnectionStrings("constr").ConnectionString
    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = "select ContactName from Customers where" & _
        " ContactName like @SearchText + '%'"
    cmd.Parameters.AddWithValue("@SearchText", prefixText)
    cmd.Connection = conn
    conn.Open()
    Dim customers As List(Of String) = New List(Of String)
    Dim sdr As SqlDataReader = cmd.ExecuteReader
    While sdr.Read
            customers.Add(sdr("ContactName").ToString)
    End While
    conn.Close()
    Return customers
End Function
tunacode
  • 65
  • 1
  • 8
  • Thanx Man, but I was thinking of using this piece of code over and over. I did this with PageMethod but then I have to copy/paste every time I need it. Anyway thanks again. – Willow Aug 07 '14 at 17:48
  • 1
    Did you review the link? I included the VB in my answer for you, I am not sure what you are trying to accomplish but certainly this shows you how to get what you want done. – tunacode Aug 07 '14 at 17:54
  • Yes, this is working.As I said, I would like to have this in WebService so that I can reuse it next time. But, if I don't find a way to make WebService work I'll have to go this way. – Willow Aug 08 '14 at 04:50
0

Set your page property EnableEventValidation="false".It will work.