How to programmatically add Bizforms on custom web part

Andrew Campkin asked on January 26, 2017 23:15

Is there any way to programmatically add a Bizform to a custom web part? I can see how to load the form, but there doesn't seem to be any way to then add it to the Controls.

Correct Answer

Zach Perry answered on January 26, 2017 23:28

You have to add the control: <cms:BizForm ID="viewBiz" runat="server" IsLiveSite="true" />

Then you can set which form to use in SetUpControl() which is called in OnContentLoaded():

                viewBiz.FormName = FormName;
                viewBiz.SiteName = SiteContext.CurrentSiteName;
                viewBiz.UseColonBehindLabel = true;
                viewBiz.AlternativeFormFullName = AlternativeFormName;
                viewBiz.ValidationErrorMessage = "There was an error";

                // Set the live site context
                if (viewBiz != null)
                {
                    viewBiz.ControlContext.ContextName = CMS.ExtendedControls.ControlContext.LIVE_SITE;
                }

formname being a property I set on the webpart. Then in OnLoad you can add: viewBiz.OnAfterSave += viewBiz_OnAfterSave;

private void viewBiz_OnAfterSave(object sender, EventArgs e)
{
    if (TrackConversionName != String.Empty)
    {
        string siteName = SiteContext.CurrentSiteName;

        if (AnalyticsHelper.AnalyticsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, RequestContext.UserHostAddress))
        {
            HitLogProvider.LogConversions(SiteContext.CurrentSiteName, LocalizationContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue);
        }
    }
}
1 votesVote for this answer Unmark Correct answer

Recent Answers


Andrew Campkin answered on January 27, 2017 02:29

Thanks for your help!

0 votesVote for this answer Mark as a Correct answer

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