---
title: Creating custom notification gateway forms
related:
  - https://docs.kentico.com/k10/custom-development/miscellaneous-custom-development-tasks/notifications-api/developing-custom-notification-gateways/creating-custom-notification-gateway-classes.md
  - https://docs.kentico.com/k10/custom-development/miscellaneous-custom-development-tasks/notifications-api/developing-custom-notification-gateways/registering-custom-notification-gateways.md
  - https://docs.kentico.com/k10/managing-website-content/configuring-the-environment-for-content-editors/setting-up-content-notifications.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The following diagram shows how the default **Email notification gateway form** is contained within the **Content subscription** web part.

![Diagram showing the components of a notification gateway form](https://docs.kentico.com/docsassets/k10/creating-custom-notification-gateway-forms/Notification_Gateway_Form_Diagram.png "Diagram showing the components of a notification gateway form")

To create a custom notification gateway form:

1. Create a new web user control (\*.ascx) and place it into your site folder in the root of your web project.

   - You can place it anywhere in your web project, the control will be included in the site's export package when in the site folder.
2. Set the control's class to inherit from the _**CMS.Notifications.Web.UI.CMSNotificationGatewayForm**_ class.
3. Override the following members of the base class:

   - **object Value** - gets or sets the value from the custom inner control (e.g. gets or sets the text of the inner TextBox in the picture above).
   - **string Validate()** – validates the inner control's value and returns an error message if the value doesn't meet the requirements of the notification gateway (e.g. the TextBox value is validated for email address format for the **Email notification gateway**).
   - **void ClearForm()** – your custom code inside this method should set the inner control to the default state; example: text of the TextBox should be cleared (set to the empty string).

### Example - Email notification gateway form

The following code samples show how to implement a custom email notification gateway form:

**EmailNotificationForm.ascx**

> **Note:** If you installed the Kentico project as a web application, you need to rename the **CodeFile** attribute on the first line to **Codebehind.**

```html

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EmailNotificationForm.ascx.cs" Inherits="CorporateSite_EmailNotificationForm" %>

<asp:Label ID="lblEmail" runat="server" />
<asp:TextBox ID="txtEmail" runat="server" CssClass="EmailNotificationForm" EnableViewState="false" />

```

**EmailNotificationForm.ascx.cs**

```csharp

using CMS.Notifications.Web.UI;
using CMS.Helpers;
using CMS.Membership;

public partial class CorporateSite_EmailNotificationForm : CMSNotificationGatewayForm
{
    #region "Variables"

    private bool mEnableMultipleEmails = false;

    #endregion

    #region "Properties"

    /// <summary>
    /// Gets or sets the email(s) from/to textbox.
    /// </summary>
    public override object Value
    {
        get
        {
            return this.txtEmail.Text.Trim();
        }
        set
        {
            this.txtEmail.Text = ValidationHelper.GetString(value, "");
        }
    }

    /// <summary>
    /// Gets or sets the value which determines whether to allow multiple emails separated with semicolon.
    /// </summary>
    public bool EnableMultipleEmails
    {
        get
        {
            return this.mEnableMultipleEmails;
        }
        set
        {
            this.mEnableMultipleEmails = value;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
       this.lblEmail.Text = (this.EnableMultipleEmails ? ResHelper.GetString("general.emails") : ResHelper.GetString("general.email")) + ResHelper.Colon;

        // Fill in the default email
        if ((!RequestHelper.IsPostBack()) && (MembershipContext.AuthenticatedUser != null) && (!String.IsNullOrEmpty(MembershipContext.AuthenticatedUser.Email)))
        {
            this.txtEmail.Text = MembershipContext.AuthenticatedUser.Email;
        }
    }

    #region "Public methods"

    /// <summary>
    /// Checks whether the input is correct email address (or multiple email addresses).
    /// </summary>
    public override string Validate()
    {
        if (this.EnableMultipleEmails)
        {
            if (!ValidationHelper.AreEmails(this.txtEmail.Text.Trim()))
            {
                return ResHelper.GetString("notifications.emailgateway.formats");
            }
        }
        else
        {
            if (!ValidationHelper.IsEmail(this.txtEmail.Text.Trim()))
            {
                return ResHelper.GetString("notifications.emailgateway.format");
            }
        }
        return String.Empty;
    }

    /// <summary>
    /// Clears the email textbox field.
    /// </summary>
    public override void ClearForm()
    {
        this.txtEmail.Text = "";
    }

    #endregion
}

```
