I have an ASPX page that calls the server with an AJAX call that is inside a javascript function. I need to process the (json) data that is sent to the server via and then return data from the server back to the client and call a function with parameters.
My ajax code
function () {
var myVar= "ooooblah";
$.ajax({
type: "POST",
url: "MyPage.aspx/TestFunc",
data: "{val:'" + myVar + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess
});
}
My code behind aspx.cs
[WebMethod]
public static void TestFunc(string val)
{
//process code here
Page.ClientScript.RegisterStartupScript(...); //tried using this but it don't work
}
The error I get when I try to compile is :
Error CS0120 An object reference is required for the non-static field, method, or property 'Control.Page'
Error CS0026 Keyword 'this' is not valid in a static property, static method, or static field initializer
Do I need to put it outside in the Page_Load? Not sure how to fix this