private void RegisterScripts()
{
List<ScriptReference> list1 = this.CollectScripts();
ScriptReference reference1 =
new ScriptReference("MicrosoftAjax.js", this, this);
ScriptManager.AddFrameworkScript(reference1, list1, 0);
if (this.PageRequestManager.IncludingWebFormsScript)
{
ScriptReference reference2 =
new ScriptReference("MicrosoftAjaxWebForms.js", this, this);
ScriptManager.AddFrameworkScript(reference2, list1, 1);
}
foreach (ScriptReference reference3 in list1)
{
this.OnResolveScriptReference(new ScriptReferenceEventArgs(reference3));
}
List<ScriptReference> list2 = ScriptManager.RemoveDuplicates(list1);
bool flag1 = false;
foreach (ScriptReference reference4 in list2)
{
string text1 = reference4.GetUrl(this, this.Control, this.Zip);
this.RegisterClientScriptIncludeInternal(
reference4.ContainingControl, typeof(ScriptManager), text1, text1);
if (!flag1 && reference4.IsFrameworkAssembly())
{
this.ConfigureApplicationServices();
flag1 = true;
}
}
}
[PersistChildren(false)]
[ParseChildren(true)]
[NonVisualControl]
public class StaticScriptManager : Control
{
public static StaticScriptManager GetCurrent(Page page)
{
return (page.Items[typeof(StaticScriptManager)] as StaticScriptManager);
}
private bool _StaticScriptEnabled = true;
public bool StaticScriptEnabled
{
get { return _StaticScriptEnabled; }
set { _StaticScriptEnabled = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!this.DesignMode)
{
if (StaticScriptManager.GetCurrent(this.Page) != null)
{
throw new InvalidOperationException("One ContentPageManager per Page!");
}
this.Page.Items[typeof(StaticScriptManager)] = this;
ScriptManager.GetCurrent(this.Page).ResolveScriptReference +=
new EventHandler<ScriptReferenceEventArgs>(OnResolveScriptReference);
}
}
private void OnResolveScriptReference(
object sender, ScriptReferenceEventArgs e)
{
if (!this.StaticScriptEnabled)
{
return;
}
ScriptReference script = e.Script;
if (script.Name != "MicrosoftAjax.js"
&& script.Name != "MicrosoftAjaxWebForms.js"
&& script.Name != "MicrosoftAjaxTimer.js"
&& !String.IsNullOrEmpty(script.Assembly))
{
return;
}
string scriptPath = ConfigurationManager.AppSettings["Atlas_StaticScriptPath"];
if (String.IsNullOrEmpty(scriptPath))
{
return;
}
script.Path = scriptPath.EndsWith("/") ?
scriptPath + script.Name : scriptPath + "/" + script.Name;
}
}
本文出自 “赵��” 博客,转载请与作者联系!