Create and use ASP.NET User Controls as regular C1 functions

The Contribution.CompositeC1Contrib.UserControlFunctions package allows you to use ASP.NET user controls as C1 functions on your website. It is based on the community-contributed functionality.

After installing the package, you can create ASP.NET user controls (ascx files) and use them as regular  C1 functions throughout the system.

How to implement

  1. Install the Contribution.CompositeC1Contrib.UserControlFunctions package (System | Packages | Available Packages).
  2. In the code editor of your choice (for example, Visual Studio), create a user control under ~/App_Data/UserControl. The folder structure is the same as for ~/App_Data/Xslt: folders become namespaces and filenames become function names.
  3. If needed, add parameters as described below.
  4. Insert the User Control function as you insert regular C1 functions (in Visual or Source Editor). Please note that in Composite C1 version 2.1.1, you can only insert User Control functions in Source mode.

Adding parameters

You can add parameters to User Control functions by declaring them as public properties. You can also specify the label, help text and the default value via the Function Parameter attribute:

[FunctionParameter("Contact Name" , "The name of the contact" , "John Doe")]
public string Name { get; set; }

You can also specify the widget for the parameter by using the 'WidgetMarkup' as a parameter to the FunctionParameter attribute and setting it to the similar markup:

[FunctionParameter("Address" , "The address of the contact", 
    WidgetMarkup = "<f:widgetfunction xmlns:f='http://www.composite.net/ns/function/1.0' name='Composite.Widgets.String.TextArea' label='' bindingsourcename=''><f:helpdefinition xmlns:f='http://www.composite.net/ns/function/1.0' helptext='' /></f:widgetfunction>")]

public string  Address { get; set; }

Important Notes

  • When inserting User Control functions on pages, please consider wrapping the page's markup with <asp:form></asp:form> as described in "Using asp:form" to avoid errors with user сontrols not being placed inside a form tag with runat=server.

Requirements

Composite C1 version 2.1.1 or later

SHARE