ErnieStings
ErnieStings

Reputation: 6423

ASP.NET onclientclick c#

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?

Upvotes: 0

Views: 5672

Answers (2)

Jan Remunda
Jan Remunda

Reputation: 7930

try this:

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ClientID + "')";

Upvotes: 6

Akash Kava
Akash Kava

Reputation: 39956

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

Try this.

Upvotes: 5

Related Questions