Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

alert

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?

like image 642
Ishan Avatar asked Dec 28 '22 09:12

Ishan


2 Answers

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?');" />
like image 90
Nicolai Avatar answered Jan 05 '23 00:01

Nicolai


jquery should do for you.

$("#ButtonId").click({
    return confirm("Are you sure you want to continue");
})
like image 38
Junaid Avatar answered Jan 05 '23 00:01

Junaid