default.aspx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Button1_Click(object sender, EventArgs e)
  6. {
  7. try
  8. {
  9. int a = Int32.Parse(TextBox1.Text);
  10. int b = Int32.Parse(TextBox2.Text);
  11. int res = a / b;
  12. Label1.Text = res.ToString();
  13. }
  14. catch (Exception ex)
  15. {
  16. if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0)
  17. {
  18. ex.Data["ExtraInfo"] = " You can't divide " +
  19. TextBox1.Text + " by " + TextBox2.Text + ".";
  20. }
  21. throw ex;
  22. }
  23. }
  24. protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
  25. {
  26. if (e.Exception.Data["ExtraInfo"] != null)
  27. {
  28. ScriptManager1.AsyncPostBackErrorMessage =
  29. e.Exception.Message +
  30. e.Exception.Data["ExtraInfo"].ToString();
  31. }
  32. else
  33. {
  34. ScriptManager1.AsyncPostBackErrorMessage =
  35. "An unspecified error occurred.";
  36. }
  37. }
  38. </script>
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40. <head runat="server">
  41. <title>Partial-Page Update Error Handling Example</title>
  42. </head>
  43. <body>
  44. <form id="form1" runat="server">
  45. <div>
  46. <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">
  47. </asp:ScriptManager>
  48. <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  49. <ContentTemplate>
  50. <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox>
  51. /
  52. <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox>
  53. =
  54. <asp:Label ID="Label1" runat="server"></asp:Label><br />
  55. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" />
  56. </ContentTemplate>
  57. </asp:UpdatePanel>
  58. </div>
  59. </form>
  60. </body>
  61. </html>