Are you sure [Prompt User Validation]

Published Saturday, November 17, 2007 1:26 AM

there's so many times when you need to ask a user "are you sure?" but you want it to be quick and painless you don't want to do one more server round trip just for that

you can always use this the javascript prompt function so confirm() but how to integrate that into your asp.net code

ok.

   1: <asp:Button id="btnDelete" runat="server" click="btnDelete_Click" text="Delete">

that's ur button

now u need some preparation to the page

go to your head tag and add a

   1: <script language="javascript"></script>

inside that tag add this script

   1: function confirmDelete()
   2: {
   3:   return  confirm("Are you sure you want to delete this item?");
   4: }

 

now that you have everything read in your page all you have to do in your c# code is this

   1: btnDelete.Attributes.Add("onclick", "return confirmDelete();"); 

 

Filed under: , ,

Comments

# DotNetKicks.com said on Wednesday, December 05, 2007 1:58 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Leave a Comment

(required) 
(required) 
(optional)
(required)