How do I ask for a confirmation when an event fire, only under certains conditions ? I'm working on the server side and I want to ask for a confirmation only if my boolean is true.
How to add a "confirm delete" option in ASP.Net Gridview?
Ok lets say you do have a grid with a button inside template column
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return check();" />
and write in your check function determine if button should raise a postback?
<script type="text/javascript">
function check() {
var doINeedToAskUserConfirmation = // Get this according to your needs
if ( doINeedToAskUserConfirmation ){
return confirm("Are you sure?");
}
return true;
}
</script>
lets say you have a button
<input type="button" id="btnConfirm" value="Proceed"/>
Make an ajax call to determine if you need any confirmation.
$("#btnConfirm").click(function(){
$.ajax({
type: "POST",
url: "some.ashx",
data: { name: "John", location: "Boston" }
}).done(function( response ) {
// lets say when response is true we will ask confirmation
if ( msg )
{
var c = confirm( "All record will be deleted. Are you sure ? ");
// Do another ajax call to complete your operation
}
});
});