ASP.Net Ajax PageMethod - save reference to DOM object

When calling ASP.Net PageMethod, we call it like this:

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

      

What's the best way to keep a reference to the htmlElement in the above example so that we can continue working with it in the onsuccess method?

Thanks for any help in advance

+2


source to share


1 answer


Due to the fact that Javascript supports closures , you don't need to worry about maintaining an element reference; since it is lexically constrained inside onSuccess (assuming you are inserting an unnamed function instead of onSuccess.)

To put it simply, the function you insert for onSuccess can already use the item reference as if it were passed as a parameter.



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

}

      

0


source







All Articles