スクリプトがすべて準備完了している場合、辞書での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);
}
}