Is it possible to disable the server side push button behavior using Javascript

Is it possible to disable the server side push button behavior using Javascript? Note. I do not want to disable the button, the user presses the button, but does not send / receive any value from the server.

scenario:

 <asp:Button ID="Button1" runat="server" Text="Submit"  onclick="Button1_Click"  OnClientClick="Check()" />

JavaScript:

function Check() 
{
  var res = confirm(" Are u sure whatYou have selected ")
  if (res) 
  {
    alert("yes");
  }
  else {
    //Here I need to disable the submit behavoiur                        
  }
 }
}
}
+3
source share
7 answers

You need to make sure UseSubmitBehavior is set to false in the markup, then you need to make sure that you return false before the javascript postback is called.


Edit:

You must return the value of your function, and then in the retrun function true if you want to receive the postback, and return false if you do not.

<asp:Button ID="Button1" runat="server" Text="Submit"  onclick="Button1_Click"  
  OnClientClick="return Check();" UseSubmitBehavior="false" />

JavaScript:

function Check()
{
     return confirm(" Are u sure whatYou have selected ");
}
+9

sure: false .

+3
<input type='submit' onclick='return false;' />

- ( asp.net.

+1
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script>
    function dostuff() {
    alert('hello');
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <% =DateTime.Now.ToString() %>
        <asp:Button ID="Mybutton" runat="server" UseSubmitBehavior="false" Text="Click"
        OnClientClick="dostuff(); return false;" />
    </div>
    </form>
</body>
</html>
0

, :

  • Javascript HTML. , . .
  • "" - . , , onclick .

else:

document.getElementById("YourFormId").onsubmit = function() { return false; }

, , , onsubmit.

0

return false, , ( __doPostBack() asp.net)

0

,

OnClientClick = "if (! Confirm ('are you sure?')) Return false;"

instead

1-OnClientClick = "return confirm (" are you sure? "))"

or

2-OnClientClick = "confirm (" are you sure? "))"

solved a problem

<asp:Button UseSubmitBehavior="false" OnClientClick="if (!confirm('are you sure?')) return false;" >
0
source

Source: https://habr.com/ru/post/1708804/


All Articles