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.
Asked
Active
Viewed 674 times
0
-
What kind of confirmation, can you explain it more clearly? For me most of time i use javascript confirmation. – ducnh Jan 09 '13 at 16:27
2 Answers
1
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
}
});
});
-
-
I feel bad to say it but, the enterprise where I'm working, do not allow me to use AJAX ... – GmodCake Jan 09 '13 at 17:25
-
@citronas yes I dont know this will work for OP. He can also do this kind of logic without JQuery. – adt Jan 09 '13 at 17:25
-
-
@adt Javascript : ok AJAX : no I can't tell you why, it's my first mounts in this entreprise – GmodCake Jan 09 '13 at 19:01
0
Depending on what kind of you events you are using, you could create a class that derives from EventArgs
and place your condition as a property (and call it MyCondition for instance) in your own class.
In the eventhandling method, you can then use
if(e.MyCondition)
{
// do something
}
Edit:
Based on you comments, I'd suggest you try to use a DetailsView for Editing, or use the GridViews Editmode if you like.
You may also take a look at the CustomValidator.

citronas
- 19,035
- 27
- 96
- 164
-
hum, it look way too hard for what I'm doing, I want to ask for a save confirmation, is there a easier way to do it ? – GmodCake Jan 09 '13 at 17:02
-
Hmm you said server-side. Save confirmation indicates client-side interaction. – citronas Jan 09 '13 at 17:04
-
I can work on both, I just need to get the response of the confirmation on the server-side ... – GmodCake Jan 09 '13 at 17:06
-
Are you talking about a control, like a checkbox and server-side validation that validates if the checkbox is actually checked? – citronas Jan 09 '13 at 17:10
-
I'm working with a aspxgridview, when the user select a row, the content of the row is loaded in some textbox, when he modify one of them, a boolean named EditorMode change to "true" and if it is true, when somethings else happen, a confirmation message shows up, and I want to get the answer given from this confirmation message on the server-side – GmodCake Jan 09 '13 at 17:15
-
-
I'm still not understanding what you call a confirmation message. A confirmation message sound like a read-only text for me, that you are creating on the server side. I'll post you two links to the MSDN, that I think could help – citronas Jan 09 '13 at 17:21
-
I'm talking of a pop-up that says "Are you sure you want to ... ?" and I want to know if he answered "Yes" or "No" – GmodCake Jan 09 '13 at 17:24