Llamando al método de la página asp.net desde javascript no funciona
Hola, estoy llamando a un método de página simple desde javascript, aquí está mi código en el marcado
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" />
en cs
[System.Web.Services.WebMethod]
public static string TestMethod(string para)
{
return "Yes this is working";
}
La alerta muestra el resultado y dice "nulo". Reviso Firebug y no veo el error de la consola.
Si cambio el TestMethod a
[System.Web.Services.WebMethod]
public static string TestMethod()
{
return "Yes this is working";
}
Y PageMethod to
PageMethods.TestMethod( function (response) { alert(response); } );
Muestra la respuesta correcta como "Sí, esto está funcionando". Sin embargo, necesito pasar el parámetro a la función. ¿Echo de menos algo?
Gracias por la ayuda.