mush_mouth_4life
mush_mouth_4life

Reputation: 111

JavaScript Yes/No Preceding ASP.NET Button Event

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

Answers (3)

Josh Mein
Josh Mein

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

Chandu
Chandu

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

Xaisoft
Xaisoft

Reputation: 46611

You can also use jQuery instead of the ugly default confirm. Here is a question addressing that.

Upvotes: 1

Related Questions