daveywc
daveywc

Reputation: 3146

Theme Image URL Rebasing asp.net

I am implementing themes to enable an existing website to be rebranded (logos, colors, images etc.) depending on the requesting URL. I understand how to do that and have got the skins working fine except for some exceptions related to the URLs of images.

Specifically I have a control property that it is not feasible to skin. Prior to implementing themes it looked like this:

<DisplayImageChecked Url="~/Images/BobIcon-Green.png" />

Obviously that will not work with themes. So after much trial and error and reading I am trying to implement it like this:

<DisplayImageChecked Url="~/AppThemes/<%= Page.Theme %>/Images/BobIcon-Green.png" />

However that does not work. The generated html looks like:

<img src="AppThemes/%3C%25=%20Page.Theme%20%25%3E/Images/BobIcon-Green.png"/>

Any pointers in the right direction would be appreciated.

David

Upvotes: 0

Views: 2498

Answers (4)

Earl Hickey
Earl Hickey

Reputation: 93

Here's the right way to go about your task:

Adorn your property with the UrlProperty attribute, this will tell ASP.NET to automatically translate your partial URL into the proper url.

Using "~/AppThemes/" + Page.Theme + "/Images/BobIcon-Green.png" will do the trick, but it's NOT the preferred way because you need to do all the work yourself and it's always good practice to leave all the work to ASP

Upvotes: 0

Matthias
Matthias

Reputation: 1

You may also use "Images/BobIcon-Green.png" as Url. ASP will take care of resolving the Url to the directory within your theme.

Upvotes: 0

HectorMac
HectorMac

Reputation: 6143

Use the binding syntax inside a databound control (watch the single vs double quotes):

<DisplayImageChecked Url='<%# "~/AppThemes/" + Page.Theme + "/Images/BobIcon-Green.png" %>' />

Upvotes: 2

Josh
Josh

Reputation: 44916

Is there a reason that you can't just dump the images in the same folder as the theme? If you put an image say for example: "image.gif" into the theme folder, then you can simply refer to it directly in your skin.

ImageUrl="image.gif"

This will resolve just fine when you apply this skin on a control in your page. Also much easier than trying to do the dynamic URL thing.

Upvotes: 0

Related Questions