One of the ways I deal with this is using the
jquery alerts[
^] plugin for jQuery
You can create a little wrapper function around the confirmation function as follows
SomeNamespace.doConfirm = function (source, message, title) {
jConfirm(message, title, function(r) {
if (r == true) {
__doPostBack(source.id, '');
}
});
return false;
};
NB: The
__doPostBack
script function is the standard way asp.net web forms postback to the server and invoke the particular event handler for the control that raised the event.
Now, you can attach the script to your button in your page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.btnSelectInvioces.Attributes.Add("onclick", "return SomeNamespace.doConfirm(this, 'Are you sure you want to do this?', 'Prompt Title');");
}
}
Now when you click on the button, you'll see a confirmation dialog on the client. No postback has happened at this point.
If you click OK, then the standard btnSelectInvioces_Click event handler will be invoked. If you click No, no postback will occur