Load Ektron widget by ID?

白昼怎懂夜的黑 提交于 2019-12-11 09:37:48

问题


I am looking for some help with an Ektron problem.

The scenario is that we have a number of widgets which sit on a number of pages. These widgets all take user input. As the user moves through the pages filling out the form we save their field responses into a session state object, these get written to a database later. When the user gets to the end of the form we want to display all the widgets that they have filled out in a read-only mode. This will act as a summary page.

We can easily set each input control on a widget to be read-only by way of a query string parameter or CMS editable field. We can also load the user responses back into the widget from session state.

What we are having an issue with is loading the CMS edited content back into the widget.

Is there a way that we can reload a previously viewed widget? Maybe by an id using the Ektron API?

We have played around with the WidgetBase.Host object but haven’t been able to make it work. We have also tried saving a whole widget object in to session state and reloading it onto another page but this hasn’t worked also.


回答1:


In your code,
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);
}

Now you can add myWidget to your page.
If you want to read its properties. First you need your widget's type. In your ASPX page, you can use <%@ Reference Control="~/widgets/YourWidget.ascx" %> Then in your code-beside file you can reference the control's type as widgets_YourWidget. You can type cast myWidget as widgets_YourWidget




回答2:


You pose an interesting situation. At the very end, I'm not sure I would use PageBuilder. If you can store the paths to each widget control file (.ascx), then I would have a .aspx page at the end that just loads each of those widgets as controls.

In order to do so, you may need to modify the widget slightly, essentially verifying that _host is not null before being used. Like so:

_host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
if (_host != null)
{
    _host.Title = "Widget Name";
    _host.Edit += new EditDelegate(EditEvent);
    _host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
    _host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
    _host.Create += new CreateDelegate(delegate() { EditEvent(""); });
}

That should allow you to use the widget as a standard .NET control, which can be added to the page dynamically when appropriate.

Unless there's a reason to keep these being loaded with the pagebuilder UI, this is the route I would take.



来源:https://stackoverflow.com/questions/12579314/load-ektron-widget-by-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!