#region JS相关
/// <summary>
/// 向页面写JS以alert信息
/// </summary>
/// <param name="msg">信息</param>
protected void AlertMessage(string msg)
{
if (ScriptManager.GetCurrent(this) != null)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),
"alert('"
+ msg.Replace("/r/n", "///r///n").Replace("'", "//'").Replace("/"", "///"")
+ "');", true);
}
else
{
Response.Write("<script language=javascript>alert('"
+ msg.Replace("/r/n", "///r///n").Replace("'", "//'").Replace("/"", "///"")
+ "');</script>");
}
}
/// <summary>
/// 通过对地址栏赋值转到指定页
/// </summary>
/// <param name="pagePath">相对本页的指定页路径</param>
protected void PageGo(string pagePath)
{
if (ScriptManager.GetCurrent(this) != null)
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "window.location.href='" +
pagePath + "';", true);
else
Response.Write("<script language=javascript>window.location.href='" + pagePath + "';</script>");
}
/// <summary>
/// 通过 javascript:window.close(); 关闭页
/// </summary>
protected void PageClose()
{
if (ScriptManager.GetCurrent(this) != null)
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "window.close();", true);
else
Response.Write("<script language=javascript>window.close();</script>");
}
/// <summary>
/// 注册Js到Body的开始部分
/// </summary>
/// <param name="jsContent">js内容,不需要 script ...</param>
protected void RegisterJSToBodyStart(string jsContent)
{
if (ScriptManager.GetCurrent(this) != null)
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), jsContent, true);
else
this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), jsContent, true);
}
/// <summary>
/// 注册Js到Body的结束位置
/// </summary>
/// <param name="jsContent">js内容,不需要 script ...</param>
protected void RegisterJSToBodyEnd(string jsContent)
{
if (ScriptManager.GetCurrent(this) != null)
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), jsContent, true);
else
this.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), jsContent, true);
}
#endregion