Is there any way to have a [System.Web.Services.WebMethod] method in a standard page in c#?
I have a c# ASPX page that I would like to have a a method for my ajax to call. I want everything to be self contained in a single file for organization and deployment purposes.
When I add that directive to a System.Web.UI.Page for example:
[System.Web.Services.WebMethod]
public static string GetText()
{
return "All finished!";
}
and try to call Page.aspx/GetText I get the full page back, not just "All Finished" as expected.
The javascript the ajax is via jQuery:
$("#btnGetData").click(function () {
var intervalID = setInterval(updateProgress, 250);
$.ajax({
type: "POST",
url: "Test.aspx/GetText",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (msg) {
$("#progressbar").progressbar("value", 100);
$("#result").text(msg.d);
clearInterval(intervalID);
}
});
return false;
});