Default User Control Function

Take a closer look at a User Control function created by default.

When you create a User Control function in the CMS Console, it will already have some sample code that you can reuse or replace with your own code.

Let's first take a look at an .ascx.cs file.

Inheriting from UserControlFunction class

All UserControl functions in C1 CMS must inherit from the class Composite.AspNet.UserControlFunction.

public partial class C1 CMSFunction : Composite.AspNet.UserControlFunction

Description

Within the partial class ("C1Function" be default) inherited from UserControlFunction, you can specify the function's description with the FunctionDescription function.

public partial class C1Function : Composite.AspNet.UserControlFunction
{
    public override string FunctionDescription
    {
        get 
        { 
            return "A demo function that outputs a hello message."; 
        }
    }
}

The description is visible in the CMS Console GUI when you edit the function properties in the Advanced view.

A User Control function inserted in Visual Editor

The description is optional but is a good practice to have one in your User Control function.

The new function comes with a sample description which you can change to your own.

Parameters

The new function also comes with a sample string parameter declared in .ascx.cs (and further used in .ascx)

[FunctionParameter(DefaultValue = "World")]
public string Name { get; set; }
You can remove this parameter altogether (and remember to remove it in the markup).

You can add your own parameters or add none.

Read more on defining parameters in User Control Functions.

.ascx file

The sample .ascx file makes use of the Name parameter declared in .ascx.cs file.

Hello <%= this.Name %>!
You are free to change the markup the way you need or totally remove it from your function.