Try our conversational search powered by Generative AI!

Linus Ekström
Oct 30, 2008
(2 votes)

Inserting XForms as dynamic content

With the introduction of dynamic content in EPiServer CMS 5 comes a lot of new posibilities for the editors to make the page more dynamic. One sample that we shipped with the R2 release was the page property plugin. This makes it possible to insert a property from another page in a xhtml editor of a page. This can for instance be used to insert a simple value type such as a copyright text that is just a string property on another page.

As we use the Property web control to present the content of the property it's possible to insert more complex objects with the page property adapter as it just loads the PropertyControl associated with the PropertyData object. One great example is the XForms property. This makes it possible to insert a form on whatever page you want that has at least one xhtml string with dynamic content enabled. For this to work as expected we had to make some changes to the public templates as the form previously often had dependancies to the actual page/user control that was used to present the form. The XFormControl now has a static event, ControlSetup, that makes it possible to add a global behaviour to the XFormControl wherever it may be instantiated. Here is the actual code that attaches event to forms that is located in the global.asax.cs file in the R2 version of the public templates:

protected void Application_Start(Object sender, EventArgs e)
            XFormControl.ControlSetup += new EventHandler(XForm_ControlSetup);

public void XForm_ControlSetup(object sender, EventArgs e)
            XFormControl control = (XFormControl)sender;

            control.BeforeLoadingForm += new LoadFormEventHandler(XForm_BeforeLoadingForm);
            control.ControlsCreated += new EventHandler(XForm_ControlsCreated);
            control.BeforeSubmitPostedData += new SaveFormDataEventHandler(XForm_BeforeSubmitPostedData);
            control.AfterSubmitPostedData += new SaveFormDataEventHandler(XForm_AfterSubmitPostedData);

This makes it possible to still have your own custom logic when a form is loaded or posted even though you have no idea of where the form might appear. If you start to develop with the public templates in the R2 release you don't have to do anything to get this working but you should be aware that you will have logic to the form events in your global.asax.cs file. If you have an old project and upgrade it to R2 you will have to move your xform event handlers from your xform template page(s) to some global place, like the global.asax.cs file (or at least to attach your event handlers globally). You still have the option to attach local event handlers for specific form pages, just be aware that you might have global events that affects the form.

Oct 30, 2008


Oct 12, 2010 10:33 AM

Thank you for your article. I need to add a mailto everytime the editor adds a text field that validates to an email address. Do you have any clues how to do that? Thanks.
/ Victor Dollero (

Please login to comment.
Latest blogs
Introducing Image Transformer - AI Assistant for Optimizely

We've got something super cool to share with you, and it's all about giving your images a fresh spin. Image Transformer, the latest feature from ou...

Luc Gosso (MVP) | Feb 26, 2024 | Syndicated blog

Welcome 2024 Winter OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Feb 26, 2024

Optimizely Opal... what it does actually do?

At Opticon 2023, Optimizely announced its first AI product Opal. AI is definitely the new tech buzzword in 2024 and with promises that AI will be...

Jon Jones | Feb 25, 2024 | Syndicated blog

How to add more Content Area Context Menu Item in Optimizely CMS 12

Hey folks, today I will share something related to Context Menu customization in the Content Area of Optimizely CMS. As you know, the content area ...

Binh Nguyen | Feb 25, 2024