How to make a theme independent reference to an image

Last post 05-25-2008 10:27 PM by pkellner. 5 replies.

Sort Posts:

  • How to make a theme independent reference to an image

    05-24-2008, 12:50 PM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    I currently have an image button as follows.  What is the simplest way to reference login.gif when my theme changes from Gray to Red for example

    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/App_Themes/Gray/Images/login.gif" />

     

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: How to make a theme independent reference to an image

    05-24-2008, 12:59 PM
    • Star
      9,462 point Star
    • kamii47
    • Member since 05-26-2005, 4:04 PM
    • Karachi, Pakistan
    • Posts 2,201

    easiest way is to do this in yourcodebehind

    ImageButton1.ImageUrl="~/App_Themes/"+ this.Theme +"/Images/login.gif";

    Kamran Shahid
    Sr. Software Engineer
    (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])

    Remember to click "Mark as Answer" on the post that helps U
  • Re: How to make a theme independent reference to an image

    05-24-2008, 2:37 PM
    • Star
      9,462 point Star
    • kamii47
    • Member since 05-26-2005, 4:04 PM
    • Karachi, Pakistan
    • Posts 2,201

    pkellner.

    R U able to solve your problem ?

    Kamran Shahid
    Sr. Software Engineer
    (MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])

    Remember to click "Mark as Answer" on the post that helps U
  • Re: How to make a theme independent reference to an image

    05-25-2008, 12:10 PM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    If I follow the suggestion above (or do it in line with a Page.DataBind()) the problem is there is no design time support and it makes life difficult for the page designer since they have this extra syntax to use.

    Is there a "nice" way to do it that keeps the page designer happy and has design time support?

    ImageUrl="<%= '~/App_Themes/' + this.Theme + '/Image/headCodeCamp.gif' %>"

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: How to make a theme independent reference to an image

    05-25-2008, 12:15 PM
    Answer
    • All-Star
      17,185 point All-Star
    • Dave Sussman
    • Member since 06-17-2002, 11:53 AM
    • UK
    • Posts 2,371
    • ASPInsiders
      TrustedFriends-MVPs

    You should store the images under the themes and set the ImageUrl in the skin file. Give the control a SkinID in both the skin file and in the page. When the theme changes the appropriate image will be used.

  • Re: How to make a theme independent reference to an image

    05-25-2008, 10:27 PM
    • All-Star
      23,823 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,579
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Thanks Dave,

    So, I'm pretty sure I know what you mean here but just in case, I googled (ok live searched) for an example.  Hard to believe (ok, not that hard) but I found myself asking the same question about 18 months ago.  Arg.  Brain freeze is the only excuse.  So, I decided best to blog the answer and maybe I'll remember it longer this time.

    Thanks again for the tip.

    http://peterkellner.net/2008/05/25/codecampwebsiteseries3/

     

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
Page 1 of 1 (6 items)