Wywołanie metody strony asp.net z javascript nie działa
Witam Wywoływam prostą metodę strony z javascript, oto mój kod na znacznikach
function OnCallSumComplete(result, userContext, methodName) {
alert(result);
}
function OnCallSumError(error, userContext, methodName) {
if (error !== null) {
alert(error.get_message());
}
}
function test(){
var contextArray = "";
PageMethods.TestMethod("test parameter", OnCallSumComplete, OnCallSumError, contextArray);
}
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
w cs
[System.Web.Services.WebMethod]
public static string TestMethod(string para)
{
return "Yes this is working";
}
alert pokazuje wynik i mówi „null”. Sprawdzam firebug i nie widzę błędu z konsoli.
Jeśli zmienię TestMethod na
[System.Web.Services.WebMethod]
public static string TestMethod()
{
return "Yes this is working";
}
I PageMethod do
PageMethods.TestMethod( function (response) { alert(response); } );
Pokazuje prawidłową odpowiedź „Tak to działa”. Jednak muszę przekazać parametr funkcji. Czy czegoś mi brakuje?
Dzięki za pomoc.