Class that provides script embedding functionality to ASP.NET pages. Features include the ability to use ResolveUrl style src urls to place script includes inline (to the control), in the Header or using standard ASP.NET ClientScript or ScriptManager. The control can also optimize

scripts if a .min.js script file is available by using the AllowMinScript property on the script.

The purpose of this control is to provide Intellisense compatible script embedding without requiring the ASP.NET AJAX ScriptManager control since that control automatically includes MS AJAX scripts even if none of the MS AJAX features are otherwise used.

Using markup the control can embed scripts like this:

<ww:ScriptContainer ID="scripts" runat="server" RenderMode="Header"> <Scripts> <Script Src="Scripts/jquery.js" Resource="jquery"></Script> <Script Src="Scripts/ui.core.js" AllowMinScript="true"></Script> <Script Src="Scripts/ui.draggable.js" ></Script> <Script Src="Scripts/wwscriptlibrary.js" Resource="wwscriptlibrary"></Script> <Script Resource="ControlResources.Menu.js" ResourceControl="txtInput" /> </Scripts> </ww:ScriptContainer>

The options on the <Script> tag can be found in the ScriptItem class. Unfortunately due to the requirement for an HtmlGeneric control (so Intellisense still works for scripts) there's no Intellisense for the properties of Script elements in markup. They do work however.

Using CodeBehind .NET code, the static Singleton ScriptContainer.Current can be used to add scripts (even if no script instance pre-exists):

ScriptContainer script = ScriptContainer.Current; script.AddScript("~/scripts/wwEditable.js","jquery"); // as known resource script.AddScript("~/scripts/wwEditable.js", true); // as .min.js

Markup scripts always have precendence over scripts embedded in code in terms of rendering order, but you can choose where scripts are rendered to individually - Header, Script, Inline or the default of InheritFromControl. This allows some control over where scripts are loaded.