Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • tc 41 posts 62 karma points
    Jul 02, 2012 @ 23:30
    tc
    0

    Custom Datatype CSS

    Hello!

    I have developed a simple datatype consisting of a div that contains a list of images.The method I have used was to create a control that inherits IUsercontrolDataEditor. I now want to include some CSS to style these elements.

    I have added the following to the code behind:

    [assembly: WebResource("UmbracoDataTypes.Styles.DataTypes.css", "text/css")]

    The project name is UmbracoDatatypes, and DataTypes.css is held in the Styles folder. I have made sure that the build option is set to EmbeddedResource.

    I then run the following code OnInit():

    string css = "<link href=\"" + Page.ClientScript.GetWebResourceUrl(this.GetType(), "UmbracoDataTypes.Styles.DataTypes.css") + "\" type=\"text/css\" rel=\"stylesheet\" />";
    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "cssFile", css, false);

    However, after copying over the dll and ascx files to the umbraco folder and adding the data type, the css is not applied. Is there something I have missed?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 03, 2012 @ 12:43
    Jeroen Breuer
    0

    I don't have any experience with this, but have a look at the source of uComponents. http://ucomponents.codeplex.com/SourceControl/list/changesets. They do the same thing.

    Jeroen

  • tc 41 posts 62 karma points
    Jul 04, 2012 @ 12:22
    tc
    0

    Hi Jeroen,
    Thanks for pointing that out. Taking a look in the source code of uComponents was a great help.
    After a bit of a struggle I now have the resources being included using the following code:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        var resourceUrl = Page.ClientScript.GetWebResourceUrl(typeof(Uploader), "UmbracoDataTypes.Styles.DataTypes.css");
        var target = Page.Header;
       
        target.Controls.Add(new LiteralControl(
            "")
        );
    }

    Edit: I'll mark this reply as the solution as it contains the code that I used in order to get round the initial problem. But thanks for pointing me in the right direction Jeroen! 

Please Sign in or register to post replies

Write your reply to:

Draft