4

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?

4
  • use javascript or jquery for this purpose
    – Nighil
    Dec 12, 2011 at 8:42
  • +1 to the idea of using JS or jQuery Dec 12, 2011 at 8:44
  • I have absolutely no idea about javascript or jquery. Can you help me out with any tutorials online for beginners? how do i use it with ASP.net? thank you @Nighil
    – Ishan
    Dec 12, 2011 at 8:44
  • have you checked out messagebox?
    – Moonlight
    Dec 12, 2011 at 8:45

2 Answers 2

9

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?');" />
2
  • <asp:Button ID="Button5" runat="server" Text="Signed" Visible="False" onclick="Button5_Click" /> this is my button code. where do i add the above code you mentioned?in a class file for buttonclick event?
    – Ishan
    Dec 12, 2011 at 8:50
  • 1
    Just add the code i printed, inside your button tag. It will fire before your Button5_Click, and Button5_Click will then only fire, if the users presses yes.
    – Nicolai
    Dec 12, 2011 at 9:02
1

jquery should do for you.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.