开发者

ASP.Net Ajax PageMethod - retain reference to DOM object

开发者 https://www.devze.com 2022-12-09 14:14 出处:网络
When calling an ASP.Net PageMethod, we call it as follows: function doSomething(htmlElement) { PageMethods.GetText(onSuccess, onFailure);

When calling an ASP.Net PageMethod, we call it as follows:

function doSomething(htmlElement)
{    
     PageMethods.GetText(onSuccess, onFailure);
}

What is the best way to retain a reference to the htmlElement in the above example, so that we may continue to work with it in the onsuccess method?

Tha开发者_开发技巧nks for any help in advance


Due to the fact that Javascript supports closures, you won't need to worry about maintaining the reference to the element; since it's lexically scoped within onSuccess(assuming you're inlining an unnamed function in the place of onSuccess.)

Simply put, the function you put in for onSuccess can already use the reference to the element as if it were passed in as a parameter.

function doSomething(htmlElement)
{         
    PageMethods.GetText(function(x, y){ var v = htmlElement /*won't be null*/   } , onFailure);

}
0

精彩评论

暂无评论...
验证码 换一张
取 消