Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
namespace JCBTMS.BLL.Admin
{
public class MsgBox
{
/**//// <summary>
/// 伺服器端彈出alert對話方塊(用於非Ajax方式)
/// </summary>
/// <param name="str_Message">提示資訊,例子:"請輸入您姓名!"</param>
public static void Alert(string str_Message)
{
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), DateTime.Now.ToString() + DateTime.Now.Millisecond.ToString(), "alert('" + str_Message + "');", true);
}
/**//// <summary>
/// 伺服器端彈出alert對話方塊(用於AJAX方式)
/// </summary>
/// <param name="str_Message">提示資訊,例子:"請輸入您姓名!"</param>
public static void AlertAjax(string str_Message)
{
ScriptManager.RegisterClientScriptBlock((Page)System.Web.HttpContext.Current.Handler, typeof(string), DateTime.Now.ToString() + DateTime.Now.Millisecond.ToString(), "alert('" + str_Message + "');", true);
}
}
}
使用Alert方法需要添加System.Web引用;而使用AlertAjax方法需要添加System.Web.Extensions引用,同時該應用程式目標框架要設定為.NET Framework 3.5。