/// <summary> /// Adds widget. /// </summary> private void AddWidget() { int widgetID = ValidationHelper.GetInteger(WidgetId, 0); // Add web part to the currently selected zone under currently selected page if ((widgetID > 0) && !String.IsNullOrEmpty(ZoneId)) { if (wi != null) { // Ensure layout zone flag if (QueryHelper.GetBoolean("layoutzone", false)) { WebPartZoneInstance zone = pti.EnsureZone(ZoneId); zone.LayoutZone = true; zone.WidgetZoneType = zoneType; // Ensure the layout zone flag in the original page template instance WebPartZoneInstance zoneInstance = templateInstance.GetZone(ZoneId); if (zoneInstance != null) { zoneInstance.LayoutZone = true; zone.WidgetZoneType = zoneType; } } // Add the widget WebPartInstance newWidget = templateInstance.AddWidget(ZoneId, widgetID); if (newWidget != null) { // Prepare the form info to get the default properties FormInfo fi = new FormInfo(wi.WidgetProperties); DataRow dr = fi.GetDataRow(); fi.LoadDefaultValues(dr); newWidget.LoadProperties(dr); // Add webpart to user's last recently used CMSContext.CurrentUser.UserSettings.UpdateRecentlyUsedWidget(wi.WidgetName); widgetInstance = newWidget; } } } }