MsgBox.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web.UI;
  5. using System.Web;
  6. namespace Bowin.Common
  7. {
  8. public static class MsgBox
  9. {
  10. private static Page Host
  11. {
  12. get
  13. {
  14. return (Page)HttpContext.Current.Handler;
  15. }
  16. }
  17. /// <summary>
  18. /// 显示提醒信息
  19. /// </summary>
  20. /// <param name="message"></param>
  21. public static void Show(string message)
  22. {
  23. Host.ClientScript.RegisterStartupScript(typeof(Page), "ShowMessageBox",
  24. string.Format("alert('{0}');", message), true);
  25. }
  26. /// <summary>
  27. /// 显示确认窗口
  28. /// </summary>
  29. /// <param name="message"></param>
  30. public static void Confirm(string message)
  31. {
  32. Host.ClientScript.RegisterStartupScript(typeof(Page), "ConfirmMessageBox",
  33. string.Format("confirm('{0}')", message), true);
  34. }
  35. /// <summary>
  36. /// 显示提醒信息并跳转到指定页面
  37. /// </summary>
  38. /// <param name="message"></param>
  39. /// <param name="url"></param>
  40. public static void Show(string message, string url)
  41. {
  42. Host.ClientScript.RegisterStartupScript(typeof(Page), "ShowMessageAndRedirct",
  43. string.Format("alert('{0}');location='{1}';", message, url), true);
  44. }
  45. /// <summary>
  46. /// 提醒并关闭当前窗口
  47. /// </summary>
  48. /// <param name="message"></param>
  49. /// <param name="refParentPage"></param>
  50. public static void ShowAndClose(string message)
  51. {
  52. Host.ClientScript.RegisterStartupScript(typeof(Page), "ShowAndClose",
  53. string.Format("alert('{0}');window.close();", message), true);
  54. }
  55. /// <summary>
  56. /// 提醒并刷新父窗口
  57. /// </summary>
  58. /// <param name="message"></param>
  59. /// <param name="refParentPage"></param>
  60. public static void ShowAndReloadParent(string message)
  61. {
  62. Host.ClientScript.RegisterStartupScript(typeof(Page), "ShowAndReloadParent",
  63. string.Format("alert('{0}');window.parent.location.reload();", message), true);
  64. }
  65. /// <summary>
  66. /// 刷新父页面
  67. /// </summary>
  68. public static void ReloadParent()
  69. {
  70. Host.ClientScript.RegisterStartupScript(typeof(Page), "ReloadParent"
  71. , "window.parent.location.reload();", true);
  72. }
  73. public static void ShowAndScript(string message, string script)
  74. {
  75. Host.ClientScript.RegisterStartupScript(typeof(Page), "ShowAndScript",
  76. string.Format("alert('{0}');{1}", message, script), true);
  77. }
  78. }
  79. }