Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

asp.net - WebMethod not called (triggered) by PageMethod in Visual Studio 2013

I have the following problem:

The call from a WebMethod is not being done on a project created in Visual Studio 2013 (ASP.NET WebForms Application). If I create a project, for example, in Visual Studio 2008 and migrate to VS 2013 works correctly. The problem only occurs when I create a new project in Visual Studio 2013. There is no error message in the console. The WebMethod is just not being called. Nothing happens. I searched a lot but found nothing about it.

ASPX code:

<%@ 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 code:

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

Has anyone tried this or know of a solution? I have no idea what to do ...

EDIT:

Guys, I discovered one more information now:

Working only in VS2013:

-New project. -Web - ASP.NET Web Application. -Select the template "Empty". -Insert a page "Default.aspx", the WebMethod works normally ...

Now, if you create a new project and select the template "WebForms", does not work ...

Can be cross-referenced? or some different setting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the solution to my problem: What prevented the WebMethod was called was the reference to "System.Web.Optimization". Not sure how he does it, but as I will not use it at the time, decided to remove:

"System.Web.Optimization" and "Microsoft.AspNet.Web.Optimization.WebForms"

It is also necessary to remove the web.config as follows:

<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>

All ok now! Thanks to everyone who helped me with the problem! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...