IT:AD:JScript:Include
Summary
Including Scripts on the page is the bare essential step to using JScript – yet with ASP.NET, etc. time is lost…
Include Statements
- Script Include statements must not be autoclosed, or things go weird in some browers.
- Script Include statement always includes
src,type="text/javascript"
ASP.NET Includes
- From ASP.NET, use this.ResolveClient() to resolve urls:
<script src="<%=this.ResolveClientUrl("~/client/scripts/jquery-ui-1.8.9.xact/js/jquery-1.4.4.min.js") %>" type="text/javascript" ></script>- Note that Css will work fine if wrapping Head is runat=server:
<link href="~/client/scripts/jquery-ui-1.8.9.xact/css/custom-theme/jquery-ui-1.8.9.custom.css" rel="Stylesheet" type="text/css" /> <script src="<%=this.ResolveClientUrl("~/client/scripts/jquery-ui-1.8.9.xact/js/jquery-1.4.4.min.js") %>" type="text/javascript" ></script>
- Important:* '~/' is not processed on Link methods unless head has runat=server.
## ASP.NET Script Registration ## * Scripts can be registered in an ASP.NET page using: *Page.ClientScript.RegisterClientScriptInclude* Adds a ref to an external Script File. * Adds a script block at the top of the rendered page. *Page.ClientScript.RegisterScriptBlock* For inserting a chunk of Script. * Output is at top of page. * Optionally can include script tags. *Page.ClientScript.RegisterStartupScript* For inserting a chunk of Script. * Output is at bottom of page. * Optionally can include script tags. *Page.ClientScript.RegisterClientScriptResource* For inserting a resource as a chunk of Script. * Resource has to be tagged withWebResourceAttribute
[assembly: WebResource("Samples.AspNet.CS.Controls.script_include.js", "application/x-javascript")]* Resource will be served by: WebResource.axd / GetWebResourceURL. * Output is at … * Wraps output in script (not-optional). * See:Page.ClientScript.GetWebResourceUrl