Registering Scripts and Styles DNAide.Web.UI.Scripts / Styles
Registering JavaScript
DNAide.Web.UI.Scripts.ScriptAide has a series of helper methods that improve on the default ASP.NET Page.ReisterClientScriptBlock functionality. If you use Page.RegisterClientScriptBlock, you will know that all JavaScript is registered immediately after the WebForm's <form runat="server"> tag. Using ScriptAide, you can specify that scripts are registered in your WebForm's <head> tag or in any other location you specify.
Registering in the <head>:
For this to work, you will need to have runat="server" in the <head> of your aspx / master file.
// Register include
ScriptAide.CurrentContext.RegisterInclude("MyScripts", "~/js/my-scripts.js");
// Register script block
ScriptAide.CurrentContext.RegisterBlock("SayHello", "alert('Hello!');", true);
Registering in another location:
To register in another location, create a PlaceHolder in your WebForm that will act as the register location. In your codebehind, you then specify the CustomRegisterControl in ScriptAide
ScriptAide.CurrentContext.CustomRegisterControl = MyPlaceHolder;
ScriptAide.CurrentContext.RegisterInclude("MyScripts", "~/js/my-scripts.js");
All scripts registered using ScriptAide will be registered at the MyPlaceHolder location.
Registering with a conditional:
The following example will register a JavaScript include with the client side conditional for Internet Explorer 6 and below only.
ScriptAide.CurrentContext.RegisterInclude("ie.js", "~/js/ie.js", "lte IE 6");
Registering Styles
DNAide also includes a StyleAide which includes a series of register methods which work in a similar fashion to ScriptAide e.g.
StyleAide.CurrentContext.RegisterInclude("Screen.css", "~/css/screen.css");
StyleAide.CurrentContext.RegisterInclude("IE.css", "~/css/ie.css", "screen", "lte IE 6");
StyleAide.CurrentContext.RegisterInclude("IE7.css", "~/css/ie7.css", "screen", "IE 7");