making server component themeable?

Discussion in 'ASP .Net Building Controls' started by Patrick F, Feb 25, 2007.

  1. Patrick F

    Patrick F Guest

    Hi, i created a server control, but how can i add my server control to the
    skin file with some default attributes?

    Here is what i get when i try:
    this.@__controlSkins[@__BuildControl__control2_skinKey] = new
    System.Web.UI.ControlSkin(typeof(LaberImage.LaberImage), new
    System.Web.UI.ControlSkinDelegate(this.@__BuildControl__control2));

    Here is the skin file:
    <asp:LaberImage ThemeName="Test1" runat="server" />

    Here is the control:
    using System;
    using System.Web.UI.WebControls;
    using System.Web.UI;

    namespace LaberImage
    {
    [Themeable(true)]
    public class LaberImage : System.Web.UI.WebControls.Image
    {
    public LaberImage()
    {
    }

    private string imageName = string.Empty;
    public string ImageName
    {
    get
    {
    return imageName;
    }
    set
    {
    imageName = value;
    }
    }
    private string themeName = string.Empty;
    public string ThemeName
    {
    get
    {
    return themeName;
    }
    set
    {
    themeName = value;
    }
    }
    protected override void OnPreRender(EventArgs e)
    {
    if ((System.Web.HttpContext.Current.Session["theme"] == null) ||
    (System.Web.HttpContext.Current.Session["theme"].ToString() == ""))
    ImageUrl = "/App_Themes/" + themeName + "/" + imageName;
    else
    ImageUrl = "/App_Themes/" +
    System.Web.HttpContext.Current.Session["theme"] + "/" + imageName;

    base.OnPreRender(e);
    }
    }
    }

    any ideas?
    Patrick
     
    Patrick F, Feb 25, 2007
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.