在您的代码中,
using Ektron.Cms.PageBuilder;
using Ektron.Cms.Widget;
// The CMS Content ID of the first page of your form.
const long otherPageId = 1036;
PageModel pm = new PageModel();
PageData pd = null;
pm.Get(otherPageId, out pd, false);
foreach (Ektron.Cms.PageBuilder.WidgetData w in pd.Widgets)
{
WidgetTypeData myWidgetType;
IWidgetTypeModel typeModel = Ektron.Cms.Widget.WidgetTypeFactory.GetModel();
typeModel.FindByControlURL(w.ControlURL, out myWidgetType);
// you may have to prefix the ControlURL with "/Widgets/" + w.ControlURL
UserControl myWidget = Page.LoadControl(w.ControlURL) as UserControl;
// _host is your page's widget host controller.
_host.PopulateWidgetProperties(ref myWidget, ref myWidgetType, w.Settings);
}
现在您可以添加myWidget
到您的页面。
如果你想阅读它的属性。首先,您需要小部件的类型。在您的 ASPX 页面中,您可以使用 <%@ Reference Control="~/widgets/YourWidget.ascx" %>
Then 在您的代码旁文件中,您可以将控件的类型引用为widgets_YourWidget
. 您可以键入 cast myWidget 为widgets_YourWidget