Ishan
Ishan

Reputation: 4028

Display a alert box in ASP.net c# web application

I want to display a alert message when a user clicks on button.

I have a button "Signed" on click of this button I want to display a alert message saying "Are you sure you want to continue?" and two buttons in this alert message box "Yes" and "No".

On click of yes button I want a update function to be executed and on click of "No" only Alert should get closed and no changes in the current page.

Please anyone can guide me how to go on with this?

Upvotes: 4

Views: 13531

Answers (2)

Nicolai
Nicolai

Reputation: 2915

You can use the OnClientClick on the button for this. Add a return confirm(); to it. It will create a javascript confirm dialog, BEFORE it fires the click event. If the user presses no, it will not trigger the OnClick event.

OnClientClick="return confirm('Are you sure you want to continue?');"

So, added to your button markup, it would look like this:

<asp:Button ID="Button5" runat="server" Text="Signed" Visible="False" onclick="Button5_Click" OnClientClick="return confirm('Are you sure you want to continue?');" />

Upvotes: 9

Junaid
Junaid

Reputation: 1755

jquery should do for you.

$("#ButtonId").click({
    return confirm("Are you sure you want to continue");
})

Upvotes: 1

Related Questions