server event never/always executed

P

phil

Hi,

When the button is clicked, the server event in the code-behind must be
executed if the user clicked on "OK" of the Confirm and not executed if
clicked on "Cancel".
I tried two ways: the first here below NEVER executes the server event and
the second way ALWAYS execute the server event!!
First way (server event never executed)
---------------------------------------
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="return confirm('are you sure?');" />
</form>
Second way (server event amways executed)
---------------------------------------------
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd();" />
</form>
<script language="javascript" type="text/javascript">
function hfd()
{return confirm("are you sure?")}
</script>

Code-behind:
-------------
Protected Sub Button1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.ServerClick
Response.Write("ok from server")
End Sub

What's the reason of this and is there a way to find the average between
never and always (executed when "OK" and not when "Cancel")?
Thanks
Phil
 
P

phil

I found my mistake: input type must be 'submit' instead of 'button'.

This of course doen't explain the strange behavior of my original problem.
The first way works now perfect, but the second way still is always
executed.
Can anybody explain me why?
Thanks
Phil
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top