Webmethod is not called (fired) through the Pagemethod

Asked

Viewed 747 times

9

I’m having trouble firing one WebMethod in a project created in Visual Studio 2013 (Webforms Application).

If I create a project, for example, in Visual Studio 2008 and migrate to Visual Studio 2013, it works correctly. If I create a new project in Visual Studio 2013 occurs the referred problem.

I searched a lot to see if it is necessary to add some key in web.config, but I found nothing about.

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

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

EDIT: Guys, one more piece of information I just found out:

Working only on VS2013:

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

Now, if you create a new project and select the "Webforms" template, it doesn’t work...

Is there no cross reference? or any different configuration?

  • You came to check if there is an error in the browser error console (Javascript). It may help to identify the problem.

  • Thanks for the return Alles. No JS error occurs... nor Warning. Just nothing happens. It would be as if the "Enablepagemethods" tag was false... but it is "true". I can only make it work when I create a project with the "Empty" template on VS2013, if I select the "Webforms" template, it doesn’t work... and my entire project is in Webforms.

2 answers

5


I found the solution to my problem: What kept the WebMethod was the reference with the System.Web.Optimization. I’m not sure how he does it, but since I won’t be using him at the moment, I’ve decided to remove:

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

It is also necessary to remove from web.config the following:

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

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

0

Buddy, the problem wasn’t because of System.Web.Optimization.

Actually, the problem is because of why To make this Pagemethod call work in your Webforms application you need to change the Routeconfig.Cs file" (located at "~/App_code/Routconfig.Cs"), as follows:

Settings.Autoredirectmode = Redirectmode.Permanent;

To:

Settings.Autoredirectmode = Redirectmode.Off;

Same goes for calls with Jquery.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.