Reputation: 111
Hi I'm trying to learn more JavaScript AJAX. Basically I would like to have a popup Yes No on a delete button that would precede the actual C# event being fired. I could do this all in C# but I know doing it client side would be beneficial as it would reduce server load.
I'm not sure exactly how to go about this. Any ideas?
Upvotes: 3
Views: 5470
Reputation: 28645
You can use the javascript function called confirm
onclick="return confirm ('Are you sure you want to delete this _____?');"
This text parameter is the text that will be shown in the modal with the yes and no.
The Yes returns true which allows the postback to continue, but the No returns false and will stop the postback.
EDIT:
As mentioned by XaiSoft and Cybernate, if you are using an ASP.NET button you can also use the OnClientClick property which will be translated to onclick by the server.
Upvotes: 3
Reputation: 82913
You can use OnClientClick
property of the asp:Button
.. along with the JS confirm..
Try something like the code below in your aspx/ascx/master:
<asp:Button id="cmdSubmit" OnClientClick="return confirm('Are you sure?')" runat="server" .../>
Upvotes: 2