2014-01-13 29 views
4

我有以下問題:的WebMethod不叫(觸發)通過PageMethod的在Visual Studio 2013

從一個WebMethod,電話不被上在Visual Studio 2013(ASP.NET Web窗體應用程序)創建的項目來完成。例如,如果我創建了一個項目,在Visual Studio 2008中遷移到VS 2013可以正常工作。只有在Visual Studio 2013中創建新項目時纔會出現此問題。控制檯中沒有錯誤消息。 WebMethod只是沒有被調用。什麼都沒發生。我搜查了很多,但一無所獲。

ASPX代碼:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestePageMethods._Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" /> 

    <script type="text/javascript"> 

     function testeClick() {    
      PageMethods.SayHello("Name");   
     } 

    </script> 

    <input type="button" value="Say Hello" onclick="testeClick();" /> 
    </form> 
</body> 
</html> 

ASPX.VB代碼:

Partial Public Class _Default 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    End Sub 

    <System.Web.Services.WebMethod(True)> _ 
    Public Shared Function SayHello(ByVal name As String) As String 
     Return "Hello " & name 
    End Function 

End Class 

有沒有人嘗試過這種或知道解決辦法嗎?我不知道該怎麼辦...

編輯:

夥計們,我發現現在多了一個信息:

只在VS2013工作:

- 新項目。網頁 - ASP.NET Web應用程序。 - 選擇模板「空」。 - 插入頁面「的Default.aspx」,將WebMethod正常工作......

現在,如果你創建一個新的項目,並選擇模板「的WebForms」,不工作...

可以是交叉引用?或一些不同的設置?

+2

Vocêvai querer dar uma olhada nesse site paraPortuguês:http://br.stackoverflow.com/ –

+2

問題需要用英語。 – thewaywewalk

+0

謝謝,我會問那裏的問題.. –

回答

3

我找到了解決我的問題的方法:阻止WebMethod被調用的是對「System.Web.Optimization」的引用。不知道他是怎麼做的,但我不會的時候使用它,決定免去:

「System.Web.Optimization」和「Microsoft.AspNet.Web.Optimization.WebForms」

它也需要刪除web.config如下:

<namespaces> 
    <add namespace="System.Web.Optimization" /> 
</namespaces> 

<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" 

namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /> 

<dependentAssembly> 
     <assemblyIdentity name="WebGrease" culture="neutral" 

publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 

現在都OK了!感謝所有幫助我解決問題的人! :)

+0

我嘗試了以上,但是這使得ScriptManager停止工作,我無法使用webopt標記。 – OmniOwl