Tuesday, 10 September 2013

Attempting to do javascript 'confirm' on a button in the code behind

Attempting to do javascript 'confirm' on a button in the code behind

I have some code on my asp.net page that looks like this:
<input type="button" onclick="if (confirm('ARE YOU SURE? This cannot be
undone except by IT at great cost!')) { PurgeCourse(); }" value="Purge
Course Comments" id="Button2" name="Button2" />
I'm replacing this with statements in the code behind. So far, my
statements looks like this:
var Button2 = new Button();
Button2.Text = "Purge Course Comments";
Button2.OnClientClick = "javascript: PurgeCourse();";
pageButtons.Controls.Add(Button2);
This works great in the button that is added and the PurgeCourse function
is called when the button is pressed.
However, I want to add a 'confirm' (as in the original page code above) so
that the user must confirm their choice. Is there a way that I can add
that same 'confirm' functionality to what I have above?

No comments:

Post a Comment