Message back from JavaScript

T

tshad

I am trying to set up a Javascript popup box that has a way of sending back
a message to asp.net on how to process some data.

At the moment I am just doing:

myNextButton.Attributes.Add("onclick", "return confirm('Are you sure you
want finish this test?');")

to attach a popup box to a button. The problem is that the buttons only say
OK and Cancel. OK will take me to the event tied to the button and Cancel,
in effect, says to do nothing and act as if the User never pressed the
button.

What I am trying to do is have something different on the button, such as
Proceed or Go Back and someway to tell asp.net on the postback which button
was pushed.

The problem is that if you press the button, the event that is tied to the
onClick button will fire, and will do any normal processing. I want it to
process based on which buttons were pushed. Is there a way to send a
message to the event telling it what was done?

Thanks,

Tom
 
P

Patrice

Not sure to follow. I would just have two distinct buttons on my ASP.NET
Page each with its own click event handler server side. You can always ask
confirmation client side as you do now when one of these buttons is
pressed...

You could also create your won dialog if you prefer (but users would have to
press one button, then choos another button plus perhaps a cancel button in
this dialog). I would just put two buttons on the source page.

Patrice
 
T

tshad

Patrice said:
Not sure to follow. I would just have two distinct buttons on my ASP.NET
Page each with its own click event handler server side. You can always ask
confirmation client side as you do now when one of these buttons is
pressed...

You could also create your won dialog if you prefer (but users would have
to
press one button, then choos another button plus perhaps a cancel button
in
this dialog). I would just put two buttons on the source page.

No, the problem is that I want to put up a warning popup window, which I am
doing now to alert the user that there is a problem and then be able to
handle the event based on which buttons he pushes. With the Confirm popup,
you only get to go on as normal or do nothing. You also can't change the
text on the buttons (I don't think).

I need to allow the user to something akin to a message box that passes back
a message that tells me what was pushed and then pass that message back to
the onClick event of the button.

Thanks,

Tom
 
P

Patrice

Humm.. Sorry but still don't really understanding. So :
- you have a button. The users click on it.
- you want then to display a dialog box with two buttons A & B. If the user
choose A you have a postback and an action, if the user choose B you have
also some action to perform.
- for some reason you can have directly both A & B buttons on the source
page (perhaps you don't know you'll have them bas this is base on some
server side condition)

You could then :
- the user presses the button
- you open your own dialog with those two buttons (suing
window.showModalDialog), you return (window.returnValue) which button was
pressed
- here based on this return value, you could call the click event of either
the hidden "A" or the hidden "B" button.
- server side this will be seen as a click that is handled either by the A
event handler or the B event handler

Patrice

--
 
T

tshad

Patrice said:
Humm.. Sorry but still don't really understanding. So :
- you have a button. The users click on it.
- you want then to display a dialog box with two buttons A & B. If the
user
choose A you have a postback and an action, if the user choose B you have
also some action to perform.
- for some reason you can have directly both A & B buttons on the source
page (perhaps you don't know you'll have them bas this is base on some
server side condition)

I don't want the buttons on the source page as I want them to really see the
problem and a popup dialog is the best way (I think).

It does work the way I have it set up. The only problem is that I have no
idea that the user pressed a button or which button was pressed in asp.net
as the button was pressed in the client side script and not the server side
script.

The way it is set up is I have a button on the page (Submit). There is no
onClick event yet.

In my code, I find some situation that might necessitate my informing the
user of something I want him to do. So I "add" the event to the "Submit"
button, before he presses it.

When he presses it, the popup dialog appears which has 2 buttons on it - OK
and Cancel. Normal for a Javascript Confirm box.

When the OK button is pushed, it goes on with normal processing for the
Submit button. If Cancel is pressed, it will do nothing.
You could then :
- the user presses the button
- you open your own dialog

Not sure how to do this.
with those two buttons (suing
window.showModalDialog), you return (window.returnValue) which button was
pressed
- here based on this return value, you could call the click event of
either
the hidden "A" or the hidden "B" button.
- server side this will be seen as a click that is handled either by the A
event handler or the B event handler

Again, not sure how to handle this, but it sounds like it might work.

Tom
 
P

Patrice

So you'll need on the first page :
- an hidden button A with its server side handler
- an hidden button B with its server side handler
- when clicking a button (not a submit button) you'll use window.open or
window.showModalDialog (please see the DHTML doc for details) to open a new
page
- on this page you have "Process method A" and "Process method B" buttons
- by using window.returnValue (see the DHTML doc) you'll return the selected
button to the caller
- in the first page, based on the return value, you should be able to call
either A.Click() or B.click() client side
- it will cause the page to postback and it should be seen by ASP.NET as if
the user had cliked the corresponding button
- in the server side handler you can then do what you intented...

Perhaps someone will come with a simpler suggestion

Patrice

--
 
T

tshad

Patrice said:
So you'll need on the first page :
- an hidden button A with its server side handler
- an hidden button B with its server side handler
- when clicking a button (not a submit button) you'll use window.open or
window.showModalDialog (please see the DHTML doc for details) to open a
new
page

The reason I am using Javascript prompt is that it is Modal (can't touch the
Parent page until I respond to the new window). Window.Open is not Modal
and ShowModalDialog only works in IE (this would have been perfect). Andy
Smith (Metabuilders) has a real good Dialog object, but it also isn't modal.

The Confirm box (Javascript) works fine, but when if the user presses the
Cancel button, it just stops. It doesn't generate and event that would
allow me to take an action.

Tom
 

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

Top