Javascript confirmation boxes..

G

Guest

Hi People,

Wondering how we display confirmation boxes to the user in order to confirm
his action, before we can proceed. How do we get back the value from the
user's action, i.e. if he selects yes, or he selected no, in to our code in
c#.net, so we can take the appropriate action. I'm not very clear on
javascript interaction with asp.net.

Hope you guys can help,

Thanks,

I.A
 
R

Ryan Trudelle-Schwarz

Wondering how we display confirmation boxes to the user in order to
confirm his action, before we can proceed. How do we get back the
value from the user's action, i.e. if he selects yes, or he selected
no, in to our code in c#.net, so we can take the appropriate action.
I'm not very clear on javascript interaction with asp.net.

Generally this is done like so:

<asp:button id="..." runat="server" text="..." onclick="return confirm('Are
you sure you want to do this?');" />

Where if false is returned from the onclick handler, the postback will not
occur. If you want to know if they select no, you'll need to wrap the confirm
in something that will return the value, something like:

<input type="hidden" runat="server" id="confirmResult" />
<asp:button ... onclick="document.getElementById('confirmResult').value =
confirm('Are you sure you want to do this?);" />

Then check for confirm result in the click handler for the button.

Hth, Rya
 
B

bruce barker

couple notes:

1) onclick for a asp:button is the server click, so you need to use the code
behind and add an attribute to do the client clcik,
2) some versions of IE 6.0 have bug where "return false", does not cancel
the postback. you need to cancel in the event

if (document.all && window.event ) event.returnValue = false; return
false;

-- bruce (sqlwork.com)



| > Wondering how we display confirmation boxes to the user in order to
| > confirm his action, before we can proceed. How do we get back the
| > value from the user's action, i.e. if he selects yes, or he selected
| > no, in to our code in c#.net, so we can take the appropriate action.
| > I'm not very clear on javascript interaction with asp.net.
|
| Generally this is done like so:
|
| <asp:button id="..." runat="server" text="..." onclick="return
confirm('Are
| you sure you want to do this?');" />
|
| Where if false is returned from the onclick handler, the postback will not
| occur. If you want to know if they select no, you'll need to wrap the
confirm
| in something that will return the value, something like:
|
| <input type="hidden" runat="server" id="confirmResult" />
| <asp:button ... onclick="document.getElementById('confirmResult').value =
| confirm('Are you sure you want to do this?);" />
|
| Then check for confirm result in the click handler for the button.
|
| Hth, Ryan
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top