I have a template inheritance question. Lets say a user opens a page, I want to be able to find all the webparts and widgets on that page even the ones that was inherited from the parents.
I have the following code that does that for just the current page. (this is code from a webpart which is on the masterpage)
protected void Page_Load(object sender, EventArgs e)
CMS.PortalEngine.PageInfo pi = CMS.CMSHelper.CMSContext.CurrentPageInfo;
CMS.PortalEngine.PageTemplateInfo pti = pi.PageTemplateInfo;
foreach (CMS.PortalEngine.WebPartZoneInstance zone in pti.WebPartZones)
zone.ZoneID = zone.ZoneID;
foreach (CMS.PortalEngine.WebPartInstance webpart in zone.WebParts)
What this does is, it takes the current page info and gets that page's template info. Once it has that it iterates through all the zones and for each zone it will get the webparts. After all is said and done, it would have iterated through all the webparts on the page.
The problem is, the webparts are on the masterpage and whenever I open a page that uses that masterpage I am able hit a breakpoint in the posted code, but it doesn't pick up any of the webparts on the masterpage. I don't know how to traverse upwards to see whether the parent template/masterpage has webparts which is to be inherited by the child.
I have tried to write a recursive method to search through pti.ParentPageInfo but that is null. Also this.Page.Master is null.
With all this said my question becomes, how can I get a collection of all the webparts/widgets on a given page including the inherited ones???
Thanks in advance