default.aspx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 ErrorProcessClick_Handler(object sender, EventArgs e)
  6. {
  7. // This handler demonstrates an error condition. In this example
  8. // the server error gets intercepted on the client and an alert is shown.
  9. throw new ArgumentException();
  10. }
  11. protected void SuccessProcessClick_Handler(object sender, EventArgs e)
  12. {
  13. // This handler demonstrates no server side exception.
  14. UpdatePanelMessage.Text = "The asynchronous postback completed successfully.";
  15. }
  16. </script>
  17. <html xmlns="http://www.w3.org/1999/xhtml">
  18. <head runat="server">
  19. <title>PageRequestManager endRequestEventArgs Example</title>
  20. <style type="text/css">
  21. body {
  22. font-family: Tahoma;
  23. }
  24. div.AlertStyle{
  25. position: absolute; width: 90%; top: 0%;
  26. visibility: hidden; z-index: 99; background-color: #ffff99;
  27. font-size: larger; font-family: Tahoma;
  28. border-right: navy thin solid; border-top: navy thin solid;
  29. border-left: navy thin solid; border-bottom: navy thin solid;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <form id="form1" runat="server">
  35. <div>
  36. <asp:ScriptManager ID="ScriptManager1" runat="server"/>
  37. <script type="text/javascript" language="javascript">
  38. Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
  39. var divElem = 'AlertDiv';
  40. var messageElem = 'UpdatePanelMessage';
  41. function ToggleAlertDiv(visString)
  42. {
  43. var adiv = $get(divElem);
  44. adiv.style.visibility = visString;
  45. }
  46. function ClearErrorState() {
  47. $get(messageElem).innerHTML = '';
  48. ToggleAlertDiv('hidden');
  49. }
  50. function EndRequestHandler(sender, args)
  51. {
  52. if (args.get_error() != null)
  53. {
  54. var errorName = args.get_error().name;
  55. if (errorName.length > 0 )
  56. {
  57. args.set_errorHandled(true);
  58. ToggleAlertDiv('visible');
  59. $get(messageElem).innerHTML = 'The panel did not update successfully.';
  60. }
  61. }
  62. }
  63. </script>
  64. <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="Server">
  65. <ContentTemplate>
  66. <asp:Panel ID="Panel1" runat="server" GroupingText="Update Panel">
  67. <asp:Label ID="UpdatePanelMessage" runat="server" />
  68. <br />
  69. Last update:
  70. <%= DateTime.Now.ToString() %>
  71. .
  72. <br />
  73. <asp:Button runat="server" ID="Button1" Text="Submit Successful Async Postback"
  74. OnClick="SuccessProcessClick_Handler" OnClientClick="ClearErrorState()" />
  75. <asp:Button runat="server" ID="Button2" Text="Submit Async Postback With Error"
  76. OnClick="ErrorProcessClick_Handler" OnClientClick="ClearErrorState()" />
  77. <br />
  78. </asp:Panel>
  79. </ContentTemplate>
  80. </asp:UpdatePanel>
  81. <div id="AlertDiv" class="AlertStyle" style="">
  82. <div id="AlertMessage" style="float: left">
  83. There was a problem processing the last request.
  84. </div>
  85. <div id="AlertLinks" style="float: right">
  86. <a title="Hide this alert." href="#" onclick="ClearErrorState()">
  87. close</a> | <a title="Send an email notifying the Web site owner."
  88. href="mailto:[email protected]" onclick="ToggleAlertDiv('hidden', 'AlertDiv')">
  89. notify</a></div>
  90. </div>
  91. </div>
  92. </form>
  93. </body>
  94. </html>