Friday, March 5, 2010

How to Show a Yes/No Confirm MessageBox Using Javascript

In This Post I'll Show you How You Can show a Confirm MessageBo using JavaScript Using Asp.Net.

I will use Javascript's confirm function which shows a Confirm MessageBox to the user. Clicking Ok will cause a postback to the Webserver and clicking Cancel will close the MessageBox and won't cause a Postback.

First of All add a Asp.Net Button to the Web Form, Now add the following markup to the OnClientClick property of the Button Control.
OnClientClick = "javascript:return confirm('Are You Sure You Want to Continue???');"

Here is the Complete markup of the Button Control.

<asp:Button ID="Button1" runat="server" OnClientClick="javascript:return confirm('Are You Sure You Want to Continue???');" Text="Button" />


Run the Web Application and Click the Button.
It will show the Confirm MessageBox to the User against which the user can act accordingly.

No comments:

Post a Comment