Skip to content Skip to sidebar Skip to footer

Asp.net Ajax Pagemethod - Retain Reference To Dom Object

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

Solution 1:

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.

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

}

Post a Comment for "Asp.net Ajax Pagemethod - Retain Reference To Dom Object"