Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.net show the confirmationbox using javascript

Dec 31, 2010
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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

5 comments :

Anonymous said...

nice blog bro. where do you work

immu said...

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

anusha said...

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

sudharsan said...

very good post

Anonymous said...

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?

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.