I have to display a client side confirmation after calculating a complex formula server side. Something like
//Server side
On ButtonClick(){
FetchRate(field1,field2,.... fieldn);
// Show Client side confirmation
// Execute server side code if confirmed client side
}
What I have done is created a client side function but my server side code always executes on postback no matter what I select client side
// Server side
ScriptManager.RegisterStartupScript(this,this.GetType(), Guid.NewGuid().ToString(), "ConfirmAction('"+ myRate +"');", true);
//Client side
function ConfirmAction(myRate) {
if (confirm('Are you sure?. Rate is exceeding '+ myRate +', proceed ?')) {
document.getElementById('hfSaveUpdate').value = 1;
return true;
}
else
return false;
}
You can use Ajax Model Popup & handle its ok & cancel button.
Launching a Modal Popup Window from Server Code:
Server Side Code:
Client-Side Code:
On ok click of the model popup, execute you server-side after conformation code.
On cancel button click, just hide the model popup window.
For more details, check this:
ModalPopup Tutorial