Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

610
Views
In ASP.NET Web Forms, how to call a page method using "get" request

In ASP.NET Web Forms, i am able to call page method using Ajax "post" request. But i am not able to call the page method using "get request".

In this case, is it possible to call page methods using "Get" request.?Could you please provide any suggestion for this? Example Code for Page method:

    [WebMethod]
    public static string GetData()
    {            
        return "test";
    }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As @vc mentioned in the comments you'll need to make use of the ScriptMethodAttribute as well as WebMethod because you want your request to be GET and not POST so change your code as follows:

[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string GetData()
{
   return "test";
}

And in the markup you can do

function ShowTestMessage() {
     $.ajax({
          type: "GET",
          url: "YourPage.aspx/GetData",
          data: {},
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function (response) {
        alert(response.d);
    }
});
}
function OnSuccess(response) {
alert(response.d);
}

<input id="ButtonId" type="button" value="Show Message"
onclick = "ShowTestMessage()" />

Don't forget to add the following reference

using System.Web.Script.Services;
using System.Web.Services;
over 4 years ago · Santiago Trujillo Report

0

Ajax GET requests to an ASP.NET Page Method?

I guess the link would be useful. It says For security reasons, ASP.Net AJAX page methods only support POST requests.

Tried decorating the method with [ScriptMethod(UseHttpGet = true)] but still the get request is not hit.

Also the msdn doc for [ScriptMethod(UseHttpGet = true)] quotes When this property is set to true, the client proxy code uses HTTP GET to call the Web service. Not sure if it works for a webmethod in web forms.

P.S : Well seems to work with the newer versions of Jquery 2.2.2. Also please be sure that you send data through query strings not using request body as in POST method.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!