Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 18th, 2013  |  syntax: None  |  size: 1.21 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <input type="submit" name="myButton" value="Do something"
  2.     onclick="javascript:WebForm_DoPostBackWithOptions(
  3.         new WebForm_PostBackOptions('myButton', '', true, '', '', false, false))"
  4.     id="myButton" />
  5.        
  6. $('#myButton').click(function () {
  7.     // do some client-side stuff
  8.  
  9.     if (someCondition) {
  10.         // don't postback!
  11.         return false;
  12.     }
  13. });
  14.        
  15. <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
  16. <script type="text/javascript">
  17.     $(function () {
  18.         var ploopButton = null;
  19.         $("#ploop").click(function (e) {
  20.             ploopButton = this;
  21.         });
  22.         $("#form1").submit(function (e) {
  23.             if (ploopButton !== null) {
  24.                 ploopButton = null;
  25.                 return confirm('are u sure?');
  26.             }
  27.             return true;
  28.         });
  29.     });
  30. </script>
  31. <form id="form1" runat="server">
  32.     <asp:Button ID="ploop" Text="ploop" runat="server" OnClick="ploop_Click" />
  33. </form>
  34.        
  35. $('#myButton').click(function (event) {
  36.     //Call prevent default on the event to prevent submitting the form
  37.     event.preventDefault();
  38.     // do some client-side stuff
  39.  
  40.     if (someCondition) {
  41.         // don't postback!
  42.         return false;
  43.     }
  44. });