Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old December 21st, 2005, 07:32 AM
Friend of Wrox
Points: 464, Level: 7
Points: 464, Level: 7 Points: 464, Level: 7 Points: 464, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: Colombo, , Sri Lanka.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default message box



Hi,

I have added an attribute to a button in page load as,
            this.btnHome.Attributes.Add("onclick","if(!confirm ('Are you sure to delete this Event?')) return false;");

and this shows the message box properly with 2 options "Ok" and "Cancel". so i added a condition inside the button's click event as,

if(!confirm('Are you sure to delete this Event?'))
   {

   }
else
   {

   }
but this shows 2 syntax errors as,
(1) The name confirn doesnot exist in the class or namespace ....
(2) Too many characters in the character literal.

how can i return whether user pressed "Ok" or "Cancel"??

nalla



__________________
nalaka hewage
http://nalakahewage.blogspot.com
  #2 (permalink)  
Old December 21st, 2005, 02:37 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are you trying to pass client side information (the result of 'confirm()') to the server? You can't do that. Not directly at least.

You can use the confirm to simply prevent 'btnHome' from firing a postback by doing this:

  this.btnHome.Attributes.Add("onclick","return confirm('Are you sure to delete this Event?');");

A 'Cancel' click in the confirm will return false and stop the button from posting the form.


If you want to actually bring back the result of the confirm to the server (and thus always do a postback) you'll have to assign the result to a hidden form element that carries the value to the server.

-Peter
  #3 (permalink)  
Old December 21st, 2005, 10:49 PM
Friend of Wrox
Points: 464, Level: 7
Points: 464, Level: 7 Points: 464, Level: 7 Points: 464, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: Colombo, , Sri Lanka.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default



Hi Peter,

   What I want to do is Pop us a message box ("'Are you sure to delete this Event?" Ok/Cancel), when user pressed the Delete button and according to the option user selects, (Ok or cancel) delete the record or just exit from the Button press event.

   That means delete the record if user pressed "Ok" or do not delete the record if user pressed "Cancel"

   So how can I do this? How can I detect whether user pressed "Ok" or "cancel" of the message box?

nalla



  #4 (permalink)  
Old December 22nd, 2005, 08:16 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

one way to do this is store the value returned from the confirm in a hidden type and access it at server side to validate the reply.

dkautilya
shuklakautilya@rediffmail.com
  #5 (permalink)  
Old December 22nd, 2005, 11:16 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You have a standard button server control. This button is rendered in the HTML as a standard form submit button.

You add a value to the 'onclick' CLIENT-side attribute:

this.btnHome.Attributes.Add("onclick","return confirm('Are you sure to delete this Event?');");

When the user clicks the button, this CLIENT-side onclick handler executes and shows the user a CLIENT-side confirmation prompt. One of two things happens:

1. User clicks 'OK'. The confirm() method returns 'true'.

2. User clicks 'Cancel'. The confirm() method return 'false'.

This value (true/false) is being returned to the CLIENT-side event handler of the button click. Now, the onclick handler of the button on the CLIENT-side will stop if it receives 'false'. Only if it receives 'true' will it continue.

Because this button is a form submit button, the form will only submit if the handler is allowed to continue executing. By returning 'false' from the confirm() method, we are stopping execution of the handler and thus stopping the form submit.

Therefore, if the form is never submitted the page never enters a postback based on that button click. So the SERVER-side onclick handler for the button server control will not fire. Thus, you do not need any test on the SERVER-side to determine if the user pressed 'Cancel' because you stopped it at the CLIENT-side.

-Peter
  #6 (permalink)  
Old December 22nd, 2005, 11:56 PM
Friend of Wrox
Points: 464, Level: 7
Points: 464, Level: 7 Points: 464, Level: 7 Points: 464, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: Colombo, , Sri Lanka.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default



Hi,

Now I understand.:) Thank you peter.

nalla





Similar Threads
Thread Thread Starter Forum Replies Last Post
Message box basie Classic ASP Basics 1 September 4th, 2008 01:09 PM
Message box in C# shikha09 C# 0 November 28th, 2006 01:24 AM
message box nalla ASP.NET 2.0 Professional 4 December 23rd, 2005 03:00 AM
Yes No Message box dbartelt Access 7 October 28th, 2005 08:16 AM





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