using System;
using System.Text;
namespace LTP.Common
{
/// <summary>
/// 在ASP.NET中彈出提示框,有ADO.NET的方便效果
/// </summary>
public class MessageBox
{
private MessageBox()
{
}
/// <summary>
/// 顯示消息提示對話框
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
public static void Show(System.Web.UI.Page page,string msg)
{
page.ClientScript.RegisterStartupScript(page.GetType(),"message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
}
/// <summary>
/// 控件點擊消息確認提示框
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control,string msg)
{
//Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
Control.Attributes.Add("onclick", "return confirm('" + msg + "');") ;
}
/// <summary>
/// 顯示消息提示對話框,並進行頁面跳轉
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳轉的目標URL</param>
public static void ShowAndRedirect(System.Web.UI.Page page,string msg,string url)
{
//Response.Write("<script>alert('帳戶審核通過!現在去為企業充值。');window.location=\"" + pageurl + "\"</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg + "');window.location=\"" + url + "\"</script>");
}
/// <summary>
/// 顯示消息提示對話框,並進行頁面跳轉
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳轉的目標URL</param>
public static void ShowAndRedirects(System.Web.UI.Page page, string msg, string url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.AppendFormat("top.location.href='{0}'", url);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 輸出自定義腳本信息
/// </summary>
/// <param name="page">當前頁面指針,一般為this</param>
/// <param name="script">輸出腳本</param>
public static void ResponseScript(System.Web.UI.Page page,string script)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");
}
}
}