How to cancel http request from javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?T3Bh?=

    #1

    How to cancel http request from javascript

    Hi,

    I'm not sure if the title is correct. Here's what I am having trouble with:
    I have a server side button control where I am calling a javascript function
    via the OnClientClick property. I also have a server side event handler to
    handle the On_Click event on the postback. I wish to cancel the postback
    based on whether the javascript function returns true or false. The problem
    is that the I never get a postback and ofcourse the On_Click event never
    fires. Here is my js:

    function ConfirmSubmissi on()
    {
    return confirm("Do you want to continue?");
    }

    I set the button OnClientClick property as follows:
    OnClientClick=" ConfirmSubmissi on(); And I do have runat server to true.

    How can I get this to work? Thanks in advance.




  • Riki

    #2
    Re: How to cancel http request from javascript

    Opa wrote:
    Hi,
    >
    I'm not sure if the title is correct. Here's what I am having
    trouble with: I have a server side button control where I am calling
    a javascript function via the OnClientClick property. I also have a
    server side event handler to handle the On_Click event on the
    postback. I wish to cancel the postback based on whether the
    javascript function returns true or false. The problem is that the I
    never get a postback and ofcourse the On_Click event never fires.
    Here is my js:
    >
    function ConfirmSubmissi on()
    {
    return confirm("Do you want to continue?");
    }
    >
    I set the button OnClientClick property as follows:
    OnClientClick=" ConfirmSubmissi on(); And I do have runat server to
    true.
    >
    How can I get this to work? Thanks in advance.
    It should be:
    OnClientClick=" return ConfirmSubmissi on();"

    The word "return" is the key word.

    --

    Riki


    Comment

    • =?Utf-8?B?T3Bh?=

      #3
      Re: How to cancel http request from javascript

      Thanks for the reply. I tried this, but the postback is never issue (i.e.
      the server side OnClick event is never fired)
      What's interesting is if I set the OnClientClick property of the button to
      "return false;" or "return true;", I never get a postback. If I leave this
      blank. I do get a postback. Shouldn't the "return true" cause the button to
      proceed to a postback
      or having any return value will stop the postback? The bottom line is I
      want to control whether the postback is fired based on the return value of a
      javascript call.
      How can this be done?



      "Riki" wrote:
      Opa wrote:
      Hi,

      I'm not sure if the title is correct. Here's what I am having
      trouble with: I have a server side button control where I am calling
      a javascript function via the OnClientClick property. I also have a
      server side event handler to handle the On_Click event on the
      postback. I wish to cancel the postback based on whether the
      javascript function returns true or false. The problem is that the I
      never get a postback and ofcourse the On_Click event never fires.
      Here is my js:

      function ConfirmSubmissi on()
      {
      return confirm("Do you want to continue?");
      }

      I set the button OnClientClick property as follows:
      OnClientClick=" ConfirmSubmissi on(); And I do have runat server to
      true.

      How can I get this to work? Thanks in advance.
      >
      It should be:
      OnClientClick=" return ConfirmSubmissi on();"
      >
      The word "return" is the key word.
      >
      --
      >
      Riki
      >
      >
      >

      Comment

      • Mark Rae

        #4
        Re: How to cancel http request from javascript

        "Opa" <Opa@discussion s.microsoft.com wrote in message
        news:DFFC46AC-9CD3-41BE-8C0B-14E4A9E55C5C@mi crosoft.com...

        Does this work for you?

        <asp:Button ID="cmdDelete" runat="server" OnClick="cmdDel ete_Click"
        OnClientClick=" return confirm('Do you want to continue?');" Text="Delete" />


        --


        Comment

        • =?Utf-8?B?T3Bh?=

          #5
          Re: How to cancel http request from javascript

          Mark, I had the UseSubmitBehavi or="False" when I changed it to true, the
          logic works as expected. However, in a related question, I don't want any
          action when the user hits the enter key, so I suppose I have to trap the
          keypresses.

          Thanks for the help.

          "Mark Rae" wrote:
          "Opa" <Opa@discussion s.microsoft.com wrote in message
          news:DFFC46AC-9CD3-41BE-8C0B-14E4A9E55C5C@mi crosoft.com...
          >
          Does this work for you?
          >
          <asp:Button ID="cmdDelete" runat="server" OnClick="cmdDel ete_Click"
          OnClientClick=" return confirm('Do you want to continue?');" Text="Delete" />
          >
          >
          --

          >
          >

          Comment

          Working...