I need to add an “are you sure” popup window to a delete button and I am not sure how to get whether the user clicked Ok or Cancel.
Here is how I do it:
string message = "Are you sure you want to delete this user?";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("return confirm('");
sb.Append(message);
sb.Append("');");
Type type = this.GetType();
ClientScript.RegisterOnSubmitStatement(type, "alert", sb.ToString());
You could just set OnClientClick on the button to:
Then the submit/postback won’t happen if the user doesn’t click OK.