Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2007, 07:05 PM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript OK/Cancel msgbox in ASP.Net

Hi all,

I know how to give a simple "msgbox" in ASP.Net / VB.Net:

Response.Write("<Script language=Javascript> window.alert('my message') </Script>")

But I can't find anwhere how to do a 2-button "msgbox", e.g., to get the user's confirmation that they really want to delete an item.

I really appreciate any help!

LenexaKS

 
Old February 1st, 2007, 11:14 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi

You can use the confirm method as below:

If (confirm("Are you sure to delete?"))
    return true;
else
    return false;

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old February 1st, 2007, 01:11 PM
Authorized User
 
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Mike,

Thanks for your reply, but I think you're assuming I know more than I do (which isn't too much)... the code you suggested doesn't work in straight VB. I've seen examples on the web where they modify the HTML, but I can't get those to work either.

What I finally found was to add the code to Page_Load:
  ibtnSave.Attributes.Add("language", "javascript")
  ibtnSave.Attributes.Add("OnClick", "return confirm('Are you sure?');")
When OK is clicked, it runs the button click event code; when Cancel is clicked it doesn't.

Again, thanks for your reply.
 -- another Mike




 
Old February 5th, 2007, 03:06 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It sounds like you are trying to mix client side behavior with server side behavior. You can not use the client side methods (alert, confirm, prompt) to bring back data to the server.

What you are seeing is that when the user answer 'OK', the postback button gets "clicked" because the onclick handler is returned 'true'. If they answer 'Cancel', the handler is return false, which basically cancels the user's click action and the form never posts.

In order to achieve what you are looking for, you need to write some more javascript to take the return value from the message box at the client, put them in a server control, such as a hidden form element, and then let the form postback so you can evaluate the resulting value (from the hidden element) and then do what you wish on the server side.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
MsgBox problem in ASP.NET amolchikurte ASP.NET 2.0 Professional 2 June 1st, 2007 01:04 AM
Convert JavaScript OK/CANCEL to VBScript timmerdfw VBScript 0 January 4th, 2007 03:42 PM
MsgBox in asp crmpicco Classic ASP Basics 2 June 24th, 2005 08:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.