2

I try to do use Ajax (through jQuery) in asp.net website (using vb.net 2.0).

Here is my .aspx page (ajax.aspx):

    <%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb" Inherits="_Ajax" %>

<!DOCTYPE html>
<html>
<head>
  <title>Calling page methods with jQuery</title>
  <style type="text/css">
    #Result {
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="Result">Click here for the time.</div>

  <script src="jquery-1.8.3.js"></script>
  <script>
      $('#Result').click(function () {
          $.ajax({
              type: "POST",
              url: "ajax.aspx/HelloWorld",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (msg) {
                  // Replace the div's content with the page method's return.
                  $("#Result").text(msg.d);
              },
              error: function (xhr, ajaxOptions, thrownError) {
                  alert("xhr.responseText= " + xhr.responseText);
                  alert("xhr.responseStatus= " + xhr.responseStatus);
                  alert("thrownError= " + thrownError);
              }
          });
      });
  </script>
</body>
</html>

And here is code-behind file (ajax.aspx.vb):

    Imports System
Imports System.Web.Services

Public Class _Ajax
    Inherits System.Web.UI.Page

    Protected Sub Page_Load()

    End Sub

    <WebMethod()> _
    Public Shared Function HelloWorld() As String
        Return "Hello: "
    End Function

End Class

When I click on my div, ajax call failed with:

System.ArgumentException: Unknown web method HelloWorld.

[EDIT]

After refresh and restart browser a lot of times, web method is found!

I try now to add a new web method, but I get error "unknown web method" again.

I think it's a cache problem.

Do you know how to force disable this kind of cache ?

4
  • 1
    you might be missing some web.config value( httpmodules) , can you see you can access scriptmanager in your page.If not you need to install ajax extension for you application. Commented Jan 11, 2013 at 13:27
  • 1
    You're right, it's better (but not enought) after installing Ajax for ASP.NET 2.0 Commented Jan 11, 2013 at 15:14
  • You problem get solved ? or still you have some issues Commented Jan 11, 2013 at 15:27
  • It's not solved. I get error "Unknown web method". I edited my first post to describe it. Commented Jan 14, 2013 at 9:19

2 Answers 2

1

Finally, paritosh answer was useful.

I had to install ASP.NET Ajax 1.0 on web server using ASP.NET 2.0.

Here is the link : http://www.microsoft.com/en-us/download/details.aspx?id=883

Then, web method is not found until i restart ISS website, I don't know why, but it's OK after restarting it.

Thanks for answers.

Sign up to request clarification or add additional context in comments.

Comments

0

change

<%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb"
 Inherits="_Ajax" %>

to

 <%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb"
 Inherits="_Ajax" ScriptManager.EnablePageMethods="true" %>

This will make all the web methods on this page visible to the JavaScript client.

1 Comment

EnablePageMethods is not available for ASP.NET 2.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.