views:

656

answers:

1

I am creating a custom composite control based off of an asp:Label control. I'd like to be able to have the label's default properties be skinable as well as additional properties that I add to my control.

But when I add a skin definition to the Default.skin file in my themes directory, and add the control to my page with the SkinId specified, I cannot figure out how to get the control to render with the Skinned properties.

Additional points:

  • My custom control is defined in a separate library/dll.
  • I added one test property, and added the [Themeable(false)] attribute. Then I set that property in the .skin file. I didn't get any errors when I tried to view the page, so it appears to me that the .skin file is not getting applied or that the control def in the skin file doesn't get matched up with the control def in the aspx page.

From the skin file:

<ctrl:ExtendedLabel SkinId="test" runat="server"
 Expandable="true" Lookup="true" Required="true"
 RequiredCssClass="required" Text="Hello" />

From the aspx page:

<ctrl:ExtendedLabel SkinID="test" runat="server"/>

From web.config:

<pages>
  <controls>
     <add tagPrefix="ctrl" namespace="MyCompany.WebControls"
          assembly="MyCompany.Web" />
  </controls>
</pages>

I added a test property to the control, marked it as [Themeable(false)] in order to test if I'd get the runtime error when setting that property in the skin file. No error.

Notice that the pages tag doesn't have a styleSheetTheme attribute. I do however, have a Base page class that overrides StyleSheetTheme property, which seems to work for everything else.

If I add the styleSheetTheme attribute to the pages tag in web.config, the skin stuff works, including getting the error if I try to set the non-Themeable property.

What's the difference? How can I get it to work with the Base page class property code?

+1  A: 

What are you getting when you try this? I just created a simple test project and was able to skin a custom property on a web custom control. My steps were:

  • Create the custom control.
  • Add [Themeable(true)] attribute to the class definition in the code-behind file.
  • Add a Label control to my custom control.
  • Add a property named "LabelText" to my custom control, which gets/sets the label controls Text value.
  • In web.config, add 'theme="TestTheme"' to the system.web/pages section.
  • In web.config, add '<add tagPrefix="mine" tagName="Test" src="~/UI/Test.ascx" />' to the system.web/pages/controls section.
  • In my Default.skin file, added '<mine:Test runat="server" LabelText="Test Text" />
  • In Default.aspx, added '<mine:Test id="test1" runat="server" />'

Load the page up and see the text "Test Text", which was only present in the Skin file.

Hopefully one of my steps above will be something you forgot, but if not, please update your question with details on what you are trying and what you are seeing.

Chris Shaffer
Walking through all of the steps above led me to find that my test page was not inheriting from the base page class. Doh! How embarrassing. Thanks for the checklist Chris
slolife