how do you detect the click event of a button in a grid row ?
I have this
column.Unbound("Delete").Width("4%").Template("<button id='deleteSite' type='button' class='btn btn-danger btn-xs' title='Delete'><i class='fa fa-remove'></i></button>").HeaderText("");
then this (just as a test)
$(document).ready(function () { $("#deleteSite").click( function() { alert('delete button clicked'); } ); });
but the code is never executed, If I specifiy an onclick in the buton definition, it works, but id prefer to detect it with an event listener
Hello Mark,
Thank you for the update. The click event only attached to one element when you use “#” selector by id, as ids should be unique. Instead if you want to setup using the listener you should select the elements based on class, for example:
<input type="button" class="button" value="Test" />
$(".button").click(function(){alert("test");});
http://stackoverflow.com/questions/24446734/jquery-click-not-working-multiple-button
If you read my message you'll see that i had already tried that and it worked ok, but id prefer to use an event listener. Why wont it work that way ?
Thank you for contacting Infragistics!
I have done some looking into this matter and I recommend wiring up the click event in the input button itself, like the following:
<input type="button" id="btn1" value="Test 3" onclick="todoMethod(${ProductID})" />
function todoMethod(ID) {//code}
As you can see in my example you can even pass in values from row of the grid that the template input is from.