I am writing a web site in vb.net.
I need to show javascript confirm box before data is inserted. so if cancel is pressed program flow stops, otherwise data is inserted.
quick help will be much appreciated !! :)

Recommended Answers

All 4 Replies

i will assume that you are using a asp.net control button for this.

<asp:Button ID="btnSave" runat="server" OnClick="Server_btnSave_Click" OnClientClick="Client_btnSave_Click" Text="Save" />

now you can add in your codebehind the Server_btnSave_Click method and in javascript write your method for Client_btnSave_Click, that way when the user click the button the first thing to run is the client side script and there you will have your confirm statement, and the workflow will continue depends on what the user click, ok or cancel...

hey, thanks, got it. but I got another doubt. Suppose I want to do some further processing depending on user's response. Like, I want to take user to some other page if he hits cancel, then what do you suggest I should do ?

you can know what the user click, the confirm method return true if the button press was Ok, so you can have something like

if(Confirm("Are you sure want to insert this?") == false)
   //method for false

you can assign the return to a var too and then do whatever you need

var a = Confirm("are you sure about this?");
if(a == true)
   //if click ok
   //if click cancel

hope that helps

Thank you for help !! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.