我们如何将多个参数传递给PageMethod的onSuccess方法?

Jan*_*nko 5 javascript asp.net pagemethods

我从javascript方法"caller"调用PageMethod"SameMethod",这样我就可以从DB中获取一些值.获取值后,控制将继续"onSuccess"方法.问题是我需要在"onSuccess"方法中使用javascript方法"caller"中的一些变量值("importantValue").

 
function caller(){
    var importantValue = 1984;   
    PageMethod.SomeMethod(param1,..., onSuccess, onFailure)
}

onSuccess方法应该是这样的:

function onSuccess(pageMethodReturnValue, importantValue ){

}

是否有可能,如果是的话,如何将多个参数(除了页面方法的返回值)传递给PageMethod的"onSuccess"方法?

感谢帮助

Geo*_*ord 12

importantValue调用PageMethod时,将您的参数作为附加参数传递.(如果您在线搜索更多信息,这通常称为上下文参数)

function caller(){
    var importantValue = 1984;   
    PageMethod.SomeMethod(param1,..., onSuccess, onFailure, importantValue)
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以访问onSuccess回调中的值,如下所示:

function onSuccess(pageMethodReturnValue, context, methodName){
    // context == 1984
}
Run Code Online (Sandbox Code Playgroud)

更新以解释@JacksonLopes的onSuccess参数在Suresh Kumar Goudampally的文章中aspalliance网站有一个很好的描述

重要的位(修改为使用我的参数名称)是:

成功回调方法有三个参数:

  • pageMethodReturnValue - 返回页面方法的输出.
  • context - 当单个回调用于多个页面方法请求时,用于处理不同的逻辑.我们还可以传递一组值作为context参数.
  • methodName - 此参数返回调用的页面方法的名称.