使用ScriptManager对象解决#region 运行客户端脚本
/// <summary>
/// 运行客户端脚本
/// </summary>
/// <param name="page">当前页对象</param>
/// <param name="script">客户端脚本</param>
public static void RunClientScript(Page page,string script,bool addScriptTag)
{
string key = Guid.NewGuid().ToString("N");
if (!page.ClientScript.IsStartupScriptRegistered(key))
{
ScriptManager.RegisterStartupScript(page,page.GetType(), key, script,addScriptTag);
}
}
public static void RunClientBlockScript(Page page, string script,bool addScriptTag)
{
string key = Guid.NewGuid().ToString("N");
if (!page.ClientScript.IsClientScriptBlockRegistered(key))
{
ScriptManager.RegisterClientScriptBlock(page,page.GetType(), key, script,addScriptTag);
}
}
#endregion