Article ID: 311945 - Last Review: April 3, 2006 - Revision: 2.6 PRB: Templates That Are Applied Programmatically Are Not Rendering
This article was previously published under Q311945 On This PageSYMPTOMS
When you try to programmatically apply a mobile StyleSheet control that contains templates, you may find that the style is not applied. You may also notice that if you apply style templates declaratively at design time, changing the style programmatically (to a non-templated style) does not remove the previously-applied templates.
CAUSE
If you apply a StyleSheet that contains DeviceSpecific templates (such as a Header Template, or a Footer Template) programmatically in code as opposed to applying declaratively at design time, you need to set the StyleSheet before the templates are instantiated at run time. The StyleSheet is not applied if you set it in an event (such as a Page_Load event) that executes after the templates have been instantiated. The form's Init event executes prior to the templates being instantiated.
Mobile controls that support templating (ObjectList, List, and SelectionList) can have templates set in other events such as the Load event for the page. RESOLUTION
You need to set the StyleReference for a Mobile Form in the form's Init event to change the templates dynamically. The following code demonstrates how to set the form's StyleReference property in the form's Init event. To use the following code, in the textbox, type in the name of the Style (templateStyle1 or templateStyle2) that you want to be applied to the form, and then click the Change Style button: STATUSThis behavior is by design. MORE INFORMATIONSteps to Reproduce the BehaviorThe following code defines a StyleSheet control at design time. The StyleSheet contains two Styles. One Style contains templates and the other does not. Clicking on one of the buttons programmatically changes the StyleReference on the form. When you run this sample code and click the Template Style button, the Style properties are applied to the form, but not to the templates.REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
310898
(http://support.microsoft.com/kb/310898/EN-US/
)
HOW TO: Dynamically Create Data-Bound Templates Using Visual Basic .NET
| Other Resources Other Support Sites
CommunityArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email

Back to the top