November Happy Hour will be moved to Thursday December 5th.

Linus Ekström
Jan 27, 2011
  4674
(3 votes)

Property/PropertyDataControl changes

Custom tag name

CMS 6 R2 introduces two minor changes to the Property and PropertyDataControl web controls. First it's possible to set a CustomTagName attribute on your property controls for your templates. If this value is set this will propagate to the created Property control and the default implementation for CreateDefaultControls in PropertyDataControl creates a html tag with the given name instead of just creating a span tag. For instance:

<Property runat="server" PropertyName="Pagename" CustomTagName="h1" />

will result in

<h1>[Pagename]</h1>

The property web control has support to copy it's attributes to the created web control. Since a custom tag is created with the HtmlGenericControl that does not inherit from WebControl some attributes might not be copied from the Property web control to the created tag control. Styles, attributes in the Attributes collection as well as the CssClass property are passed on to the end control. Example:

<Property runat="server" PropertyName="Pagename" CustomTagName="h1" CssClass=”myheadingclass” />

will result in

<h1 class=”myheadingclass”>[Pagename]</h1>

If you have a custom property control and want to apply the attribute copying PropertyDataControl has two overloads of a method called CopyWebAttributes that can either take a WebControl or a HtmlControl. These are virtual so that you can customize the actual attribute copying in your control.

Control creation for null value properties

Another change is that PropertyDataControl has a new protected virtual method called ShouldCreateDefaultControls. If this returns false the call to CreateDefaultControls is never made from PropertyDataControl. The default implementation only makes a call to CreateDefaultControls if the PropertyData.IsNull property returns false. This can be a breaking change since a developer may have an implementation for the CreateDefaultControls that creates controls even if the IsNull-property returns true. In this case, the fix is to override the ShouldCreateDefaultControls method and always return true.

Note: these changes are not available in the CMS 6 R2 Beta release.

Jan 27, 2011

Comments

Jan 27, 2011 02:48 PM

Nice tweak, simple but could prove useful

Oskar Zetterberg
Oskar Zetterberg Jan 27, 2011 02:56 PM

Excellent, i´ve been waiting for something like this. Now we can get the markup the way we want it without the need of ugly hacks :).

Jan 27, 2011 04:08 PM

How does this relate to the AttributeSourceControl property? I've used that to extract information from the container control (EPiServer:Property), like this:
https://www.coderesort.com/p/epicode/browser/MakingWaves.EPiImage/6.x/EPiImage/Properties/EPiImagePropertyControl.cs#L175

Did I do it wrong?

Jan 28, 2011 04:03 PM

Steve: Your code will still work. It's up to the implementation in CreateDefaultControls to make use/copy any attributes. It's also up to this method to decide if the custom tag name makes any sense for your property. We have gone through the built in property controls and implemented support to either directly create a tag with the custom name or in some cases (for instance links) wrap the inner control in the custom tag (

[Link text]

).

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog