Re: JavaScript confirm



If you don't return "false", the event will arrive to the server. Now you
need to pass the user's choice in a hidden input control:

btnClick.Attributes.Add("OnClick",
"javascript:myForm.inhConfirmResponse.value = confirm('Are you sure you wish
to exit?') ? 'true' : 'false'");

and in the aspx page:

<input type="hidden" id="inhConfirmResponse" runat="server" />

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1161870937.419387.34490@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
If Cancel is
clicked, the event won't propagate to the server

But I want the event to propogate so that ASP.NET can invoke a
different sub-routine.

As already said, I want the confirm dialog to come up when a Button is
clicked. The code snippet I showed in post #1 does this. Now I want to
invoke a sub-routine when the user clicks 'OK' which can be easily done
using the OnClick event of the Button control using the following code
snippet (assume that this ASPX page is named 'Proceed.aspx')

<script runat="server">
Sub Page_Load(.....)
btnClick.Attributes.Add("OnClick", "javascript:return
confirm('Are you sure you wish to exit?');")
End Sub

Sub OKClicked(obj As Object, ea As EventArgs)
Response.Write("You clicked OK")
End Sub
</script>
<form runat="server">
<asp:Button ID="btnClick" OnClick="OKClicked" Text="PROCEED"
runat="server"/>
</form>

But if the user clicks 'Cancel' in the confirm dialog, I want ANOTHER
sub-routine named, say, 'CancelClicked' to be invoked. How do I invoke
the sub 'CancelClicked' when the user clicks 'Cancel' in the confirm
dialog? This is where I am getting stuck.

Actually prior to coming to this ASPX page named 'Proceed.aspx' that
has the above Button control, a few records entered by a user in
different Form fields get inserted in a temporary SQL Server 2005 DB
table. A user clicks this Button control; the JavaScript confirm dialog
with 'OK' & 'Cancel' buttons pops-up. If the user clicks 'OK', records
in the temporary table will be transferred to another DB table after
which, the records in the temporary table will get deleted. However, if
the user clicks 'Cancel' in the confirm dialog, then WITHOUT
transferring the records from the temporary table to the other DB
table, the records in the temporary table should get deleted.

That's precisely the reason why I want to execute a sub-routine even
when 'Cancel' in the confirm dialog is clicked.


Eliyahu Goldin wrote:
Are you asking on the server side? Your code already does it. If Cancel
is
clicked, the event won't propagate to the server.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1161853312.870679.122810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have gone through a no. of posts in this NewsGroup regarding my
problem but alas, couldn't come across one which would have helped me
in resolving the issue. My problem is this:

An ASPX Form has a Button. When the Button is clicked, I want a
JavaScript confirm dialog to pop-up with the options 'OK' & 'Cancel'. I
have done this using the following code:

Sub Page_Load(....)
btnClick.Attributes.Add("OnClick", "javascript:return confirm('Are
you sure you want to exit?');")
End Sub

where 'btnClick' is the name of the Button.

The problem is how do I find out which of the 2 buttons, 'OK' or
'Cancel', has a user clicked? Any one can help me out with this?

My primary intention is if the user clicks 'OK' in the confirm dialog,
then function1 should get executed but if the user clicks 'Cancel',
then function2 should get executed.

In JavaScript, if 'OK' is clicked, then confiorm returns 1; if 'Cancel'
is clicked, then confirm returns 0.




.