ExclusivePostBackBasicsCS.aspx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" >
  5. <head runat="server">
  6. <title>Make a PostBack Exclusive Example</title>
  7. </head>
  8. <body>
  9. <form id="form1" runat="server">
  10. <div>
  11. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  12. <script type="text/javascript" language="javascript">
  13. </script>
  14. <script type="text/javascript" language="javascript">
  15. Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
  16. var exclusivePostBackElement = 'Button1';
  17. var exclusiveFlag;
  18. function InitializeRequest(sender, args)
  19. {
  20. var prm = Sys.WebForms.PageRequestManager.getInstance();
  21. if (prm.get_isInAsyncPostBack())
  22. {
  23. if (typeof exclusiveFlag != 'undefined' & exclusiveFlag )
  24. {
  25. args.set_cancel(true);
  26. // Set UI elements to inform users that
  27. // new asynchronous postback was canceled.
  28. }
  29. }
  30. else
  31. {
  32. exclusiveFlag = false;
  33. if (args.get_postBackElement().id == exclusivePostBackElement)
  34. {
  35. exclusiveFlag = true;
  36. }
  37. }
  38. }
  39. </script>
  40. </div>
  41. </form>
  42. </body>
  43. </html>