views:

70

answers:

1

Is there any way to use a specific usercontrols depending on which theme the site is using?

Scenario: I am using themes in my asp.net project. I am going to have same codebase and different look and feel and so using themes & skins. Now the problem is if I want to have different headers & footers (which are usercontrols) depending on the type of site, how can we do with the help of themes.

A: 

Yes, control hierarchies can be modified with themes.

This is made possible by ITemplate properties that are Themeable.

If, for instance, you had a custom control that simply has a themeable Contents property you could say:

<custom:MyThemeableControl runat="server">
    <Contents>
    ... any valid *.skin markup here
    </Contents>
</custom:MyThemeableControl>

Now you could swap out the controls inside Contents for different themes as follows - for ThemeA you would have the following skin:

<custom:MyThemeableControl runat="server">
    <Contents>
        <asp:Button runnat="server" />
    </Contents>
</custom:MyThemeableControl>

And for ThemeB you would have the following skin:

<custom:MyThemeableControl runat="server">
    <Contents>
        <asp:TextBox runnat="server" />
    </Contents>
</custom:MyThemeableControl>

Then this page would render a Button under ThemeA and a TextBox under ThemeB:

<@Page Theme="ThemeA">
<custom:MyThemeableControl runat="server" />

<@Page Theme="ThemeB">
<custom:MyThemeableControl runat="server" />
Nariman