fussy fussy - 1 year ago 94
Javascript Question

Click Gridview button using jQuery

I have an asp datagrid with a remove button and I want to click on the button, enable the modal for the confirmation message and when okay is clicked in the modal, to call the normal C# code behind that would've been called if the modal was not there. I'm trying to achieve this using jQuery. Below is the code:


<asp:linkbutton id="btnRemoveProperty" runat="server" class="btnRemove" ClientIDMode ="AutoID" CommandName="RemoveProperty"> REMOVE <asp:linkbutton>


var btnConfirm;
var button;
$(".btnRemove").click(function () {
if (btnConfirm == 1) {
btnConfirm = "";
return true;
else {
button = $(this).attr('id');
return false;

$("#btnDelete.click(function () { //button inside the modal
btnConfirm = 1;
$("#" + button).click(); //is not doing anything

The problem is that $("#" + button).click() is not doing anything even though it has the gridview button ID. It should have called the $(".btnRemove").click and then the code behind would've been called.

Answer Source

Try this:

$("#btnDelete").click(function () { //button inside the modal
  btnConfirm = 1;
  var el = $("#" + button); 
  return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download