I have html table which was generated from server side :
DataTable dt2 = new Claims_Service().ASO_MOD_Get_Nulls();
myGridView.DataSource = dt2;
myGridView.DataBind();
The table has rows and in each row there is a button.
in client side I write :
$(".myGridView").on('click', '.myButton', function ()
{
...
}
Now lets say I need to re-bind in server side. ( rebind === full postback and regenerate page)
Should I use jQuery remove function in order to release the events and prevent memory leaks before I rebind ?
Also , Would your answer will be different if I wrote :
$(".myGridView .myButton").on('click',function ()
It's not necessary to remove handlers when you are reloading the page via a full POST or GET request. In any event, remove() will remove the elements from the DOM, not simply remove the event handlers. To remove event handlers you want to use off().
If written like so:
$(".myGridView").on('click', '.myButton', function () { /* your code */ });
memory leaks are not a concern as you are pattern matching on dom bubble to all the ".myButton" occurances.
while
$(".myGridView .myButton").on('click',function () { /* your code */ });
is attaching to all the indivual ".myButton" occurrences
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With