resolve dynamic controls in c#

Rita Mikusch asked on September 6, 2018 02:00

Hi,

My webpart displays either HtmlTextA, or HtmlTextB, depending on the resolution of a conditional ... very straightforward.

It works great ... unless HtmlTextA or HtmlTextB contain dynamic controls ... for example a form or widget.

How do I get those dynamic controls resolved? Thank you!

if (somethingHappens) { DisplayContent.Text = HtmlTextA; } else { DisplayContent.Text = HtmlTextB; }

Recent Answers


Arun Kumar answered on September 6, 2018 06:32

Check this post. You can use something like below

CMS.ExtendedControls.ControlsHelper.ResolveDynamicControls(this.plcContent);
1 votesVote for this answer Mark as a Correct answer

Rita Mikusch answered on September 6, 2018 19:51 (last edited on December 10, 2019 02:31)

Thank you, unfortunately it doesn't work. Maybe that's because of all the changes in kentico (the article is from 2011).

Perhaps there's a better way to do what I'm doing....

I have a 'page type' field that I'm adding a FORM to. Then I copy the value of that 'page type' field into a web part field using a macro:

{%CurrentDocument["PageTypeField_HtmlContainingBizForm"]|(identity)GlobalAdministrator%}

Then in the webpart's code:

<asp:PlaceHolder runat="server" ID="plcHolder">
<asp:Label ID="DisplayContent" runat="server" Text=""></asp:Label>
</asp:PlaceHolder>

DisplayContent.Text = WebPartField_HtmlContainingBizForm;

// then I try to resolve the controls ... neither of these two attempts worked:

// Resolving the dynamic controls didn't work
ControlsHelper.ResolveDynamicControls(this.plcHolder);

// Resolving the macros didn't work either
DisplayContent.Text = MacroResolver.Resolve(DisplayContent.Text);

Both give me bizform widget code instead of the actual bizform:
{^widget|(name)BizForm|(BizFormName)ChapterFeedbackForm|(widget_displayname)On-line+form^}

Thank you, Rita.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.