views:

796

answers:

2

I have an ImageButton with an onclientclick js function attached:

deleteButton = new ImageButton();
deleteButton.ID = "deleteRiskButton" + planRisk.Id;
deleteButton.ImageUrl = "../../Images/deleteButton.gif";
deleteButton.Click += new ImageClickEventHandler(deleteButton_Click);
deleteButton.OnClientClick = "removeRowAfterDeletion('" + deleteButton.ID + "')";

Inside this JavaScript function i have a dialog making sure the user intended to delete the item in question.

function removeRowAfterDeletion(buttonId)
   {
        var deleteConfirmationDialog = confirm("Are you sure you want to remove this risk from your plan?.")
        return deleteConfirmationDialog;
   }

I was under the impression that if the onclientclick function returns false then the postback would not occur. However, even if the I click cancel the deleteButton_Click c# function is called.

Any idea what the problem is?

+5  A: 
deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ID + "')";

Try this.

Akash Kava
i didn't copy your post :-)
Jan Remunda
Using "deleteButton.ClientID" will be a better bet.
o.k.w
+6  A: 

try this:

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ClientID + "')";
Jan Remunda
It's indeed just the ClientID
Jan Jongboom