As I work on integrating a new control into a project that already contains ASP.Net controls, I am faced with the challenge of managing multiple .Net classes and JavaScript files. Each control consists of a .NET class (inheriting ScriptControl) along with a corresponding JavaScript file that is added to the assembly as a WebResource.
[assembly: WebResource("Assembly.Namespace.WidgetControl.js", "text/javascript")]
[assembly: WebResource("Assembly.Namespace.CogControl.js", "text/javascript")]
In order to avoid duplicating code and maintain clean programming practices, I am looking to inherit from a class in another JavaScript resource rather than copying and pasting code between files. However, ensuring proper WebResource loading order is crucial for this inheritance to work effectively.
For instance, if I want to inherit from the class in WidgetControl.js
and extend it using ThingaMahBobControl.js
, does the sequence of adding WebResource references impact the load order? Adding the reference for ThingaMahBob after Widget may seem logical but will it guarantee the correct load order?
Since the control must inherit the abstract ScriptControl and implement GetScriptReferences()
, arranging the enumerable collection of script references in the desired order becomes essential:
protected override IEnumerable<ScriptReference> GetScriptReferences()
{
List<ScriptReference> refs = new List<ScriptReference>();
refs.Add(new ScriptReference("Assembly.Namespace.WidgetControl.js", this.GetType().Assembly.FullName));
refs.Add(new ScriptReference("Assembly.Namespace.ThingaMahBobControl.js", this.GetType().Assembly.FullName));
return refs;
}