WebService的Webmethod不会触发AJAX AutoCompleteExtender和UpdatePanel

时间:2014-08-07 17:34:46

标签: asp.net ajax vb.net updatepanel autocompleteextender

这是代码:

<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

我做了什么:

  1. 我在更新面板外移动了文本框 - 0分
  2. 将WebMethod从共享更改为实例 - 0分
  3. 将WebService移至root - 0分
  4. 将PostBack = true和触发器添加到UpdatePanel,文本框作为触发器 - 0分
  5. 使用自动完成文本框创建新的网站,而不使用UpdatePanel - 10分
  6. 我错过了什么?

2 个答案:

答案 0 :(得分:0)

我只在c#中完成了这个,我可以给你一个c#例子如果你请求它,否则检查这个资源,它应该可以帮助你实现这个目的。 http://www.aspsnippets.com/Articles/ASP.Net-AJAX-Control-Toolkit-AutoCompleteExtender-without-using-Web-Services.aspx

从链接:

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

答案 1 :(得分:0)

设置你的页面属性EnableEventValidation =&#34; false&#34;。它会工作。