Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Design A Widget which loads other widgets ? View modes: 
User avatar
Member
Member
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

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 6/21/2010 8:09:49 AM
   
RE:Design A Widget which loads other widgets ?
Hi,

You will need to go through the collection in PageTemplateInstance, where you can ge the zone information and which web parts/widgets are in the zones and you will compare it to currently added web part/widget.

Best regards,
Juraj Ondrus