I've got it *mostly* working, but I need to include a colorbox (http://colorpowered.com/colorbox/) for one of my displays. This requires jQuery, jQuery's colorbox, and a colorbox.css with a bunch of images. Since it's a custom control, I can't just drop the items in a directory and link to them. My control is called DoctypeSelector and here is the code as it is now:
using System; using System.Collections.Generic; using System.Web.UI.WebControls; using System.Web.UI;
Registering JavaScript/CSS inside an Umbraco Custom Control for a New Data Type
I'm working on a custom data type for Umbraco based on Tim's Blog Post: http://www.nibble.be/?p=90
I've got it *mostly* working, but I need to include a colorbox (http://colorpowered.com/colorbox/) for one of my displays. This requires jQuery, jQuery's colorbox, and a colorbox.css with a bunch of images. Since it's a custom control, I can't just drop the items in a directory and link to them. My control is called DoctypeSelector and here is the code as it is now:
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
[assembly: System.Web.UI.WebResource("DocTypeSelector.Styles.colorbox.css", "text/css")]
[assembly: System.Web.UI.WebResource("DocTypeSelector.Scripts.jquery.colorbox-min.js", "text/js")]
[assembly: System.Web.UI.WebResource("DocTypeSelector.Control.DoctypeSelector.js", "text/js")]
namespace DocTypeSelector
{
public class DoctypeSelectorControl : Panel
{
private HyperLink lnkSelector;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (lnkSelector == null)
{
lnkSelector = new HyperLink();
}
lnkSelector.Text = "Select...";
lnkSelector.NavigateUrl = "#";
lnkSelector.CssClass = "selectTool";
System.Web.UI.HtmlControls.HtmlLink cssLink = new System.Web.UI.HtmlControls.HtmlLink();
cssLink.Href = cssLink.Href = Page.ClientScript.GetWebResourceUrl(this.GetType(),"DocTypeSelector.Styles.colorbox.css");
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(cssLink);
this.Controls.Add(new LiteralControl("<div style=\"display: none\"><div id=\"selectBox\">Welcome!</div></div>"));
this.Page.ClientScript.RegisterClientScriptInclude(
"DocTypeSelector.DoctypeSelector.js",
this.Page.ClientScript.GetWebResourceUrl(typeof(DoctypeSelectorControl), "DocTypeSelector.Control.DoctypeSelector.js"));
this.Page.ClientScript.RegisterClientScriptInclude(
"DocTypeSelector.jquery.colorbox-min.js",
this.Page.ClientScript.GetWebResourceUrl(typeof(DoctypeSelectorControl), "DocTypeSelector.Scripts.jquery.colorbox-min.js"));
}
}
}
It looks like the javascript and css are "attempting" to be embedded because i see extra links in the rendered page, but when I click them I get a:
The resource cannot be found.
Thanks in advanced for any and all help!
Hi Chris,
If you haven't already, you might need to set the Build Action to Embedded Resource in Visual Studio?
Otherwise are you sure the namespace/folders are correct?
-Tom
Hi Tom,
Sorry, should have mentioned that, but yes, all javascript and css files are set to embedded resource.
Chris
is working on a reply...