Introduction
Here I will explain how to show the confirmation box using JavaScript in asp.net.
Description
I have one button whenever user clicks on that button I need to show one confirmation box if user clicks on ok button I need to execute code in button click event or if he clicks on cancel button nothing to display and the page should not be postback. How we can implement that one in our application? To implement this concept follow these steps
Design your aspx page like this
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Confirmation Box Example</title>
<script type="text/javascript">
//Confirmation box sample
function ConfirmationBox() {
var result = confirm("Are you sure you want to continue?");
if (result == true) {
return true;
}
else {
var lbl = document.getElementById('lbltxt');
lbl.innerHTML = "";
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClientClick="return ConfirmationBox()" onclick="btnSubmit_Click" />
<asp:Label ID="lbltxt" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
|
In code behind button click event write the following code
protected void btnSubmit_Click(object sender, EventArgs e)
{
lbltxt.Text = "Welcome to Confirmationbox page";
}
|
Demo
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
5 comments :
nice blog bro. where do you work
Hi suresh,I need to take one combo box and in dat combo box i need to bind the all stored procedures from backend,by clicking on particular s.p. below the combo box i need to display how many parameters required for a selected s.p.(i need to display dat parameters in a lables) then i need to enter the data and the data should be displayed in a gridview on button click(button name is execute)..This is the exact requirement..can u help me plz..
sir pls help me out...how to use javascript in child page which is derived from master page.it works in normal asp.net page
very good post
hello suresh,
Can I override window.confirm function options Yes,No insted of Yes,Cancel?
if we do this can you provide code for this?
Note: Only a member of this blog may post a comment.