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.
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