Callback.aspx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <%@ Page Language="C#" %>
  2. <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. string _callbackResult;
  6. public string GetCallbackResult () {
  7. return _callbackResult;
  8. }
  9. public void RaiseCallbackEvent (string eventArgs) {
  10. if (eventArgs == "CCC")
  11. throw new Exception ("CCC");
  12. _callbackResult = eventArgs;
  13. }
  14. string _callbackEventRef_1;
  15. string _callbackEventRef_2;
  16. string _callbackEventRef_3;
  17. protected override void OnInit (EventArgs e) {
  18. base.OnInit (e);
  19. _callbackEventRef_1 = ClientScript.GetCallbackEventReference (this, "'AAA'", "clientCallback", null, "errorCallback", true);
  20. _callbackEventRef_2 = ClientScript.GetCallbackEventReference (this, "'BBB'", "clientCallback", null, "errorCallback", true);
  21. _callbackEventRef_3 = ClientScript.GetCallbackEventReference (this, "'CCC'", "clientCallback", null, "errorCallback", true);
  22. }
  23. </script>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head runat="server">
  26. <title>Untitled Page</title>
  27. </head>
  28. <body>
  29. <script type="text/javascript">
  30. function clientCallback(result, ctx)
  31. {
  32. alert(result);
  33. }
  34. function errorCallback(result, ctx)
  35. {
  36. alert("error");
  37. alert(result);
  38. }
  39. </script>
  40. <form id="form1" runat="server">
  41. <div>
  42. <a href="javascript:<%=_callbackEventRef_1 %>" id="A1">_callbackEventRef_1</a><br />
  43. <a href="javascript:<%=_callbackEventRef_2 %>" id="A2">_callbackEventRef_2</a><br />
  44. <a href="javascript:<%=_callbackEventRef_3 %>" id="A3">_callbackEventRef_3</a><br />
  45. </div>
  46. </form>
  47. </body>
  48. </html>