Class ScriptContainer

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.

System.Object
  System.Web.UI.Control
    Westwind.Web.Controls.ScriptContainer

public class ScriptContainer : Control, IDisposable

Remarks

Only one instance of this component can exist on the page otherwise an exception is thrown.

Class Members

MemberDescription
Constructor
AddScript Adds a script item to the page with full options
public void AddScript( ScriptItem script );

public void AddScript( string scriptUrl,
ScriptRenderModes renderMode,
bool allowMinScript );

public void AddScript( string scriptUrl );

public void AddScript( string scriptUrl,
bool allowMinScript );

Dispose
public virtual void Dispose();
Current Returns a current instance of this control if an instance is already loaded on the page. Otherwise a new instance is created, added to the Form and returned.
MinScriptExtension Script extension for minimized or packed scripts. Used only for entries that AllowMinScript=True.
RenderMode Determines where scripts are rendered by default. Defaults to script which renders using ClientScript or ScriptManager.
Scripts Collection of ScriptItems

Requirements

Namespace: Westwind.Web.Controls
Assembly: westwind.ajaxtoolkit.dll

See also:

Class ScriptItem

  Last Updated: 7/15/2008 | © West Wind Technologies, 2008