Working on a custom Window control derived from Coolite Window control, I wanted to ensure that my script file for the custom Window gets included at an appropriate place in the page header before the ClientInitScript for my custom control.

Although you can directly add script files to the Page using the Page.ClientScript.RegisterClientScriptInclude method, there was a probability of generating javascript errors in case you file got included before the core Coolite/ExtJs javascript files, as your js would almost certainly be using namespace, classes & methods from these files, and therefore should be included after these files.

A bit of searching around in the Coolite code led me to the Coolite.Ext.Web.ClientScriptAttribute, which you can decorate your class with to ensure that the appropriate js file get included at an appropriate place. Here’s how you can use it.



<Coolite.Ext.Web.InstanceOf(ClassName:="Imbibe.Controls.Ext.QuickSearch")> _
<Coolite.Ext.Web.ClientScript(WebResource:="Imbibe.Web.QuickSearch.js", Type:=GetType(QuickSearchWindow))> _
<CLSCompliant(True)> _
Public Class QuickSearchWindow
	Inherits Coolite.Ext.Web.Window
End Class



{syntaxhighlighter brush: csharp;fontsize: 100; first-line: 1; }[Coolite.Ext.Web.InstanceOf(ClassName=”Imbibe.Controls.Ext.QuickSearch”)]
[Coolite.Ext.Web.ClientScript(WebResource=”Imbibe.Web.QuickSearch.js”, Type=GetType(QuickSearchWindow))]
public class QuickSearchWindow : Coolite.Ext.Web.Window

Because I was using js files embedded into an assembly, I used the WebResource and Type properties on the attribute to specify the location for the js file. In case you are referring a non-embedded file, you should use FilePath property on the same attribute, instead of the above two.
Moreover, you can also specify a different path for Debugging using the PathDebug or WebResourceDebug properties.

Also take care that I am talking of Coolite (i.e. lesser than 1.0 versions of the re-branded  Ext.Net whose public release is overdue). With Ext.Net, many of the Attributes have been converted to properties. Thus there is an InstanceOf property instead of the InstanceOfAttribute in Ext.Net 1.0. However, I was unable to find a corresponding property for the ClientScriptAttribute in Ext.Net 1.0. I will update this blog post, or write a new one when I figure that out for 1.0.

<Coolite.Ext.Web.InstanceOf(ClassName:=”Imbibe.Controls.Ext.QuickSearch”)> _
<Coolite.Ext.Web.ClientScript(WebResource:=”Imbibe.Web.QuickSearch.js”, Type:=GetType(QuickSearchWindow))> _
<CLSCompliant(True)> _
Public Class QuickSearchWindow
Inherits Ext.Window
End Class