server event never/always executed

Discussion in 'ASP .Net Web Controls' started by phil, Jun 6, 2006.

  1. phil

    phil Guest

    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
     
    phil, Jun 6, 2006
    #1
    1. Advertising

  2. phil

    phil Guest

    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

    "phil" <> wrote in message
    news:...
    > 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
    >
    >
     
    phil, Jun 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    1
    Views:
    457
    Henry S. Thompson
    Dec 1, 2005
  2. Kevin
    Replies:
    4
    Views:
    430
    Irrwahn Grausewitz
    Oct 17, 2003
  3. Sunny Mohan
    Replies:
    0
    Views:
    213
    Sunny Mohan
    Apr 5, 2004
  4. fakessh

    semple code accept never executed

    fakessh, Sep 14, 2012, in forum: C Programming
    Replies:
    11
    Views:
    498
    Kaz Kylheku
    Sep 15, 2012
  5. Íéêüëáïò Êïýñáò

    A certainl part of an if() structure never gets executed.

    Íéêüëáïò Êïýñáò, Jun 11, 2013, in forum: Python
    Replies:
    161
    Views:
    1,288
    Thomas Rachel
    Jun 26, 2013
Loading...

Share This Page