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 Commented Dec 12, 2011 at 8:42
  • +1 to the idea of using JS or jQuery Commented 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 Commented Dec 12, 2011 at 8:44
  • have you checked out messagebox? Commented 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?');" />
Sign up to request clarification or add additional context in comments.

2 Comments

<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?
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.
1

jquery should do for you.

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.