help.axcms.netAxinom Logo
Save Save Chapter Send Feedback

How to add a custom control to contact module


General approach

In general you add a new dynamic control to your solution. This control should inherit from BaseContactControl and implement IEnterEventHandler, if you want to bind enter event to your send button of your contact form. In the base class the general structure is defined.

The base class already has properties that most of the contact controls use (Pflichtfeld = mandatory field, Breite = width, Bezeichnung = usage = explaining text in confirmation mails, Horizontal = alignment for radiobuttonlists and checkboxlists), so you do not need to create those parameters properties again.

The property "MyControl" must be overridden with a special type, we will talk about that later.

If you want to register certain events, you can use the "RegisterEvents" function. Anything that must be translated can be passed to the Translate function, so you do not have to take care about the resourcemanager etc by yourself.

The functions "FillControl", "FillfromRequest", "FillFromUser", "SetExtendedProperties" can be overridden.

Let's talk about MyControl property now. The control defined here must inherit from the IBaseAxinomControl.


There are already existing classes like TextBoxAxinomControl, CheckBoxListAxinomControl ... what you can do is either just use one of these existing ones, write your own classes that inherit from them, or write new classes that must derive from the control class.

In your control in function "Check" you can implement some logic that checks if control is filled out correct, in function "Clear" you can clear the selection (important for clear button functionality) and in function "Read" you can read out the selection the user has made. The result passed back is a string.

Those functions are called by send button later when form i sposted and that's how your control gets read out.

If you have your control now, you can add its tag to your new dynamic control and override "MyControl" property there and return your control. In base class in function "SetProperties" the base properties are assigned to your control.

        protected void SetProperties()
            MyControl.ID = "_" + ContactModuleContext.EncodeUsageForID(this.Bezeichnung) + "AxinomControl";
            MyControl.Usage = this.Bezeichnung;
            MyControl.Duty = this.Pflichtfeld;
            MyControl.ToolTip = this.Bezeichnung;

If you have other properties now, you can assign them in "SetExtendedProperties" function.

If you want to prefill your control you can override the "Fill..."-functions.

To bind the enter event just implement the interface and add the following function:

       #region IEnterEventHandler Members

        public void BindControlToButton(Control control, Control button)
            BindControlToButton(myControl, button.ClientID);


Now you must define your new dynamic control in CMSSite.xml. of course you can write an editor for it as usual. Here is also an base class that can help you.

If you inherit your editor from this class, all default properties are set, just name your controls in aspx the way they are defined here.

Practical example

You want to have a textbox that checks the entered zip code. What you have to do for that ...

1. Create a new dynamic control.
2. Inherit the code behind from BaseContactControl and implement IEnterEventHandler.
3. Create a custom text box class.
4. Add this new control to your ascx of your dyn control.
5. Override functions, you need to override.
6. Create an editor.
7. Add new dynamic control to your CMSSite.xml.

The code sample is available here...