0

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?

1
  • Now you got the code working, I'm wondering, why do you need to pass the ID of the button? Perhaps you want to extend the function for "removeRowAfterDeletion" further. You can always use "return removeRowAfterDeletion(this);" to pass in the instance of the button. Commented Sep 9, 2009 at 13:48

2 Answers 2

6

try this:

deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ClientID + "')";
Sign up to request clarification or add additional context in comments.

1 Comment

It's indeed just the ClientID
5
deleteButton.OnClientClick = "return removeRowAfterDeletion('" + deleteButton.ID + "')";

Try this.

1 Comment

Using "deleteButton.ClientID" will be a better bet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.