如果脚本全部准备好注册,则在字典中进行简单检查,这IsClientScriptIncludeRegistered
是一种非常快速的检查,无需太多代码。
public bool IsClientScriptIncludeRegistered(Type type, string key)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
return ((this._registeredClientScriptBlocks != null) &&
this._registeredClientScriptBlocks.Contains(
CreateScriptIncludeKey(type, key, false)));
}
RegisterClientScriptInclude
另一方面,包含更多代码,直到达到现有的检查。
internal void RegisterClientScriptInclude(Control control, Type type, string key, string url)
{
IScriptManager scriptManager = this._owner.ScriptManager;
if ((scriptManager != null) && scriptManager.SupportsPartialRendering)
{
scriptManager.RegisterClientScriptInclude(control, type, key, url);
}
else
{
this.RegisterClientScriptInclude(type, key, url);
}
}
internal void RegisterClientScriptInclude(Type type, string key, string url, bool isResource)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (string.IsNullOrEmpty(url))
{
throw ExceptionUtil.ParameterNullOrEmpty("url");
}
string script = "\r\n<script src=\"" + HttpUtility.HtmlAttributeEncode(url) + "\" type=\"text/javascript\"></script>";
this.RegisterScriptBlock(CreateScriptIncludeKey(type, key, isResource), script, ClientAPIRegisterType.ClientScriptBlocks);
}
internal void RegisterScriptBlock(ScriptKey key, string script, ClientAPIRegisterType type)
{
switch (type)
{
case ClientAPIRegisterType.ClientScriptBlocks:
this.RegisterScriptBlock(key, script, ref this._registeredClientScriptBlocks, ref this._clientScriptBlocks, false);
break;
case ClientAPIRegisterType.ClientScriptBlocksWithoutTags:
this.RegisterScriptBlock(key, script, ref this._registeredClientScriptBlocks, ref this._clientScriptBlocks, true);
break;
case ClientAPIRegisterType.ClientStartupScripts:
this.RegisterScriptBlock(key, script, ref this._registeredClientStartupScripts, ref this._clientStartupScripts, false);
break;
case ClientAPIRegisterType.ClientStartupScriptsWithoutTags:
this.RegisterScriptBlock(key, script, ref this._registeredClientStartupScripts, ref this._clientStartupScripts, true);
break;
}
if (this._owner.PartialCachingControlStack != null)
{
foreach (BasePartialCachingControl control in this._owner.PartialCachingControlStack)
{
control.RegisterScriptBlock(type, key, script);
}
}
}
private void RegisterScriptBlock(ScriptKey key, string script, ref ListDictionary scriptBlocks, ref ArrayList scriptList, bool needsScriptTags)
{
if (scriptBlocks == null)
{
scriptBlocks = new ListDictionary();
scriptList = new ArrayList();
}
if (!scriptBlocks.Contains(key))
{
Tuple<ScriptKey, string, bool> tuple = new Tuple<ScriptKey, string, bool>(key, script, needsScriptTags);
scriptBlocks.Add(key, null);
scriptList.Add(tuple);
}
}