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" RenderMode="HeaderTop"></script> <script Src="~/Scripts/ui.core.js" AllowMinScript="true"></Script> <script Src="~/Scripts/ui.draggable.js"></script> <script Src="~/Scripts/ww.jquery.js" Resource="Westwind.Web.Controls.ww.jquery.js"></script> <script Resource="ControlResources.Menu.js" ResourceControl="txtInput"></script> </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 in the page) 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. <seealso>Class ScriptItem</seealso>
System.Object
System.Web.UI.Control
Westwind.Web.Controls.ScriptContainer
public class ScriptContainer : Control, IDisposable
Member | Description | |
---|---|---|
Constructor | ||
AddScript | Adds a script item to the page with full options public void AddScript( ScriptItem script ); public void AddScript( string scriptUrl, public void AddScript( string scriptUrl ); public void AddScript( string scriptUrl, | |
Dispose | public virtual void Dispose(); | |
LoadControlScript | Helper function that is used to load script resources for various AJAX controls Loads a script resource based on the following scriptLocation values: public void LoadControlScript( Control control, string scriptLocation, string resourceName, ScriptRenderModes renderMode ); public void LoadControlScript( Control control, public void LoadControlScript( Control control, | |
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 |