default.aspx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. <script runat="server">
  5. protected void Button_Click(object sender, EventArgs e)
  6. {
  7. System.Threading.Thread.Sleep(3000);
  8. }
  9. </script>
  10. <html xmlns="http://www.w3.org/1999/xhtml" >
  11. <head id="Head1" runat="server">
  12. <title>UpdateProgress Example</title>
  13. <style type="text/css">
  14. #UpdatePanel1, #UpdatePanel2, #UpdateProgress1 {
  15. border-right: gray 1px solid; border-top: gray 1px solid;
  16. border-left: gray 1px solid; border-bottom: gray 1px solid;
  17. }
  18. #UpdatePanel1, #UpdatePanel2 {
  19. width:200px; height:200px; position: relative;
  20. float: left; margin-left: 10px; margin-top: 10px;
  21. }
  22. #UpdateProgress1 {
  23. width: 400px; background-color: #FFC080;
  24. bottom: 0%; left: 0px; position: absolute;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <form id="form1" runat="server">
  30. <div>
  31. <asp:ScriptManager ID="ScriptManager1" runat="server" />
  32. <script type="text/javascript">
  33. var prm = Sys.WebForms.PageRequestManager.getInstance();
  34. prm.add_initializeRequest(InitializeRequest);
  35. prm.add_endRequest(EndRequest);
  36. var postBackElement;
  37. function InitializeRequest(sender, args) {
  38. if (prm.get_isInAsyncPostBack())
  39. {
  40. args.set_cancel(true);
  41. }
  42. postBackElement = args.get_postBackElement();
  43. if (postBackElement.id == 'ButtonTrigger')
  44. {
  45. $get('UpdateProgress1').style.display = "block";
  46. }
  47. }
  48. function EndRequest (sender, args) {
  49. if (postBackElement.id == 'ButtonTrigger')
  50. {
  51. $get('UpdateProgress1').style.display = "none";
  52. }
  53. }
  54. function AbortPostBack() {
  55. if (prm.get_isInAsyncPostBack()) {
  56. prm.abortPostBack();
  57. }
  58. }
  59. </script>
  60. <asp:Button ID="ButtonTrigger" runat="server" Text="Refresh Panel 1" OnClick="Button_Click" />
  61. <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
  62. <ContentTemplate>
  63. <%=DateTime.Now.ToString() %> <br />
  64. The trigger for this panel
  65. causes the UpdateProgress to be displayed
  66. even though the UpdateProgress is associated
  67. with panel 2.
  68. <br />
  69. </ContentTemplate>
  70. <Triggers>
  71. <asp:AsyncPostBackTrigger ControlID="ButtonTrigger" />
  72. </Triggers>
  73. </asp:UpdatePanel>
  74. <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
  75. <ContentTemplate>
  76. <%=DateTime.Now.ToString() %> <br />
  77. <asp:Button ID="Button2" runat="server" Text="Refresh Panel" OnClick="Button_Click"/>
  78. </ContentTemplate>
  79. </asp:UpdatePanel>
  80. <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel2" >
  81. <ProgressTemplate>
  82. Update in progress...
  83. <input type="button" value="stop" onclick="AbortPostBack()" />
  84. </ProgressTemplate>
  85. </asp:UpdateProgress>
  86. </div>
  87. </form>
  88. </body>
  89. </html>