You are hereBlogs / rahul's blog / Coolite - Ensuring appropriate inclusion of script files for Custom Controls

Coolite - Ensuring appropriate inclusion of script files for Custom Controls


rahul's picture

By rahul - Posted on 21 March 2010

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.

VB.NET:

 

<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

C#:

 

[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 : 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

 

 

 

You have to override Resources property instead using of the ClientScript/ClientStyle attributes. 

Resources property returns list of the ClientStyleItem/ClientScriptItem

For example, just see TreeGrid class to investigate how correctly to override the Resources property

rahul's picture

Hi vlad, thanks again for complementing the blog post with your comments. I hope your comment applies to Ext.Net 1.0 or later!!

Post new comment

The content of this field is kept private and will not be shown publicly.

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.