anji.anjee-gmail
-
6/10/2010 2:47:58 PM
Design A Widget which loads other widgets ?
Hi ALL,
I want to wrirte a new webpart which in turn convert it to a widget.
The functionality of these widget will be like these ,
1 .When i click on a button "Design My Default Page",it should load may b 9 widgets ino 3 zones (3 each).
2.When one of the widget which is going to be load is already on the page ,then dont' load that widget just ignore loading.
i was able to achieve solution to first question through the following method private void AddWidget(string ZoneId, string WidgetName, PageInfo pi) { if ((ZoneId != "") && (CMSContext.CurrentAliasPath != "") && (WidgetName != "")) {
// Get source data
if (pi != null) { // Get template instance PageTemplateInstance pti = null; pti = CMSPortalManager.GetTemplateInstanceForEditing(pi);
if (pti != null) { // Get the zone WebPartZoneInstance zone = null; zone = pti.EnsureZone(ZoneId);
if (zone != null) {
// Get the web part by code name WidgetInfo wi = WidgetInfoProvider.GetWidgetInfo(WidgetName);
if (wi != null) { WebPartInstance wpi = null; wpi = pti.AddWidget(ZoneId, wi.WidgetID);
if (wpi != null) { // Prepare the form info to get the default properties
FormInfo fi = new FormInfo(wi.WidgetProperties); FormFieldInfo ffi = new FormFieldInfo(); ffi.Name = "Container"; ffi.DefaultValue = ConfigurationSettings.AppSettings["CMSDefaultWebpartContainer"].ToString();
fi.AddFormField(ffi);
DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr);
wpi.LoadProperties(dr);
// Add webpart to user's last recently used CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName);
}
// Save the changes CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, pti, zone.WidgetZoneType, CMSContext.ViewMode, tree);
}
}
} }
} }
But i dont have solution to second question ,how do i know the widget which i'm adding is already in the page.
So please someone guide me in the direction.
Thanks In Advance Anjee
|