How do widgets Settings / Values map to .ascx.cs public properties?

  • Disclaimer: I have just been forced to solve some issue with our website that uses Ektron, and I have never seen Ektron in my life until now, so this is probably a novice question but I've read a ton of the help file and nothing has helped me.

    The thing I'm struggling with is that we have:

    - .ascx files that have public properties expose, for example:

    public String PayOrderUrl { get; set; }

    - When I look at a Page in the Ektron WorkArea that uses this ascx control, the Content tab that displays that property under the "Settings" bullet and if I edit the page in Ekron, I can set a value for that.

    I have no idea how the Ektron page knows about PayOrderUrl, unless it reads the ascx code at some point...

    One of my main goals would be to be able to add another property in the ascx.cs file and then set a value for it in Ektron but again I have idea how this all works together.

    From what I see, the documentation doesn't help me. Can anyone answer this or point me to documentation that explains it?

    Thanks in Advance,

    Posted 1/13/2017 @ 11:23 AM
    • Posted by BHetland
    • Joined on 1/13/2017
    • 1 total post
  • So I'll match your disclaimer for one of my own: There's more than one way to make these things work and I've seen some wild architectures when it comes to widgets (I disagree with a fair number). However, here's what's usual.

    The ASCX files inherit not only from the base control type in .NET, but also from IWidget. 

    Those properties usually are paired with an attribute called WidgetDataMember that may or may not set a value - that value becomes the default for that property. So for a "widget property" that gets its value saved to the DB, you'll usually see them like so:

    [WidgetDataMember("Some value")]
    public string PayOrderUrl {get; set;}

    There also will be somewhere in the code behind a directive that says to save the widget data members. 

        protected void SaveButton_Click(object sender, EventArgs e)
            if (Page.IsValid)
                EnteredText = ReplaceEncodeBrackets(uxText.Text);

    Here is a bit of my own code, in it you'll see the _host.SaveWidgetDataMembers() method.

    That method can look at the properties of the control that have the aforementioned attribute and save the currently assigned values to the XML that's stored as the configuration for the page.

    Now, if you want to add a new property, you'll have do to a couple of things. 

    1. Set up your property as mentioned above, with the WidgetDataMember attribute.
    2. Add a form field in the Widget's Edit view (most widgets use a MultiView with one configured view being Edit).
    3. Ensure that the new property has the value from the form applied to it.
    4. Call SaveWidgetDataMembers() to save the new configuration

    For a complete widget example, see my relatively simple EmbedHtml widget posted to this site's code share.

    Posted 1/20/2017 @ 5:24 PM
    • Posted by eGandalf@Brightfind
    • Joined on 1/20/2017
    • 3 total posts

What Do You Think of our New Design?


Have more to say? We’d love to hear it!