No pain, no gain.
分类: 系统运维
2011-02-16 21:38:05
//在页面顶部添加脚本
if (!Page.ClientScript.IsClientScriptBlockRegistered("myscriptKey"))//判断是否已经存在相同//键值的ScriptBlock
{
string myScript = @"function AlertHello(){alert('hello xuanhun!!');}";//脚本内容
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscriptKey", myScript,true);
}
//在页面底部添加脚本
if(!Page.ClientScript.IsStartupScriptRegistered("footscriptkey"))
{
string CallScript = @"AlertHello();";
Page.ClientScript.RegisterStartupScript(this.GetType(), "footscriptKey", CallScript, true);
}
// 添加对js文件的引用
if(!Page.ClientScript.IsClientScriptIncludeRegistered("incluedeKey"))
{
string IncludeScript = @"/js/ShowHello.js";
Page.ClientScript.RegisterClientScriptInclude("includeKey", IncludeScript);
}