Programmatically change widget template.
How would one go about programmatically changing the template that widget is using?
Anyone out there?
Still looking for an answer.
Hi Erik,
Thanks Craig, but I'm trying to do something a bit different. I have a widget that adds other widgets to the page based on some criteria. When I add these widgets to the page I want to set a specific template on them. For instance, I may be adding a NewsView to the page and I want to set it to use a custom widget template that I created for its detail view. I don't want to overwrite the existing templates as I use them in other scenarios. I just want to be able to define what template a widget uses when I add it to the page programmaticaly.
I've been thinking about this over the weekend, so I'm sorry I haven't chimed in before now.
I haven't tried this, but I discovered some code in the Charity SDK sample initialization script (Global.asax) that demonstrates initializing an EventsView control and assigning it to a template:
var eventsControl =
new
EventsView();
eventsControl.MasterViewName =
"EventsFrontendDateList"
;
eventsControl.ControlDefinition.GetDefaultDetailView().TemplateKey = SampleUtilities.GetControlTemplateKey(
typeof
(Telerik.Sitefinity.Modules.Events.Web.UI.Public.DetailsView),
"Event Details with iCal"
);
Thanks, that looks promising! I'll give it a shot and let you know how it turns out.
:) it works!
newsControl.DetailViewDefinition.TemplateKey =
"B2B1FDB7-F0A8-429A-8C64-ECC02EFC4ECF"
;
var contentView =
new
DynamicContentView();
contentView.DynamicContentTypeName =
"Telerik.Sitefinity.DynamicTypes.Model.Promos.Promo"
;
contentView.DetailViewDefinition.DataItemId = dataItemId;
contentView.ControlDefinition.GetDefaultDetailView().TemplateKey =
"D0CC1EB5-DA98-4B44-8200-9C69AAF3A2D5"
;