I've got two projects, one is a control library and another is my main project. From the control library I am currently using a user control and some css files which are embedded in the control library.
I can use the embedded CSS files in my main project by doing the following from my user control's PreRender event:
// Register the default CSS resource
string includeTemplate = "<link rel='stylesheet' text='text/css' href='{0}' />";
string includeLocation = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyCompany.ControlLibrary.WebNotify.WebNotify.css");
LiteralControl cssInclude = new LiteralControl(String.Format(includeTemplate, includeLocation));
((System.Web.UI.HtmlControls.HtmlHead)Page.Header).Controls.Add(cssInclude);
I thought it would then make sense to include all my javascript files in a similar fashion, so I included the embedded javascript file doing the following:
// Register the js
string includeTemplate = "<script type='text/javascript' src='{0}'></script>";
string includeLocation = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyCompany.ControlLibrary.Scripts.MyScript.js");
LiteralControl jsInclude = new LiteralControl(String.Format(includeTemplate, includeLocation));
((System.Web.UI.HtmlControls.HtmlHead)Page.Header).Controls.Add(jsInclude);
Now, the CSS all works perfectly, however my JS functions throw Object Required exceptions when trying to call them.
Am I going about this the correct way? Or is there a better way of including an embedded js file from another assembly into another project?