.Net后台弹出脚提示-注册本的两种方法
方法一:
/// <summary>
/// 显示Alert提示信息
/// </summary>
/// <param name="_strMessage"></param>
public void ShowAlert(string _strMessage)
{
ScriptStartup("alert('" + _strMessage.Replace("\r", @"\r").Replace("\n", @"\n").Replace("'", "\"") + "');");
}
/// <summary>
/// 写客户端脚本(RegisterStartupScript)
/// </summary>
/// <param name="_scriptContent"></param>
public void ScriptStartup(string _scriptContent)
{
ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script language='javascript'>" + _scriptContent + "</script>");
}
/// <summary>
/// 写客户端脚本(RegisterStartupScript)
/// </summary>
/// <param name="_scriptContent"></param>
public void ScriptStartupMsg(string msg)
{
ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('" + msg + "');", true);
}
ShowAlert("你要弹出的消息");//调用
方法二:
public void RegisterScript(string script, bool isAfter)
{
if (isAfter)
ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), Guid.NewGuid().ToString(), script, true);
else
ClientScript.RegisterClientScriptBlock(typeof(System.Web.UI.Page), Guid.NewGuid().ToString(), script, true);
}
RegisterScript("你要弹出的消息", true);