• Decrease Text SizeIncrease Text Size

Module Designer Custom Control

Posted Date: 5/2/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
In order to create a custom control for the module designer please follow the steps below.
1. Download Template or grab the code from below and move it to the Uploads directory of your site. If that control will need to be in more than one site create a folder with my_ prefix in the root of your development site and move the control there. (you may need to fix the code file and inherits the path later).
2. Copy Following

[cp:control key='SampleControl' cpsys_src='/Uploads/SampleControl/CustomControl.ascx' Parameter1='Hello word'  /]

into the particular view of the module designer and save the record.
3. Navigate to the view which contains your new custom control.
Please note that more parameters can be placed into the control a using similar manner.

CustomControl.ascx

<%@ control language="C#" autoeventwireup="true" codefile="~/Uploads/SampleControl/CustomControl.ascx.cs" inherits="Centralpoint.WebSite.Uploads.SampleControl.CustomControl" %>

<br><div id="cphContent_dvTest"></div>


CustomControl.ascx.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Drawing;
using Centralpoint;
using Centralpoint.Web;
using Centralpoint.Web.UI;
using Centralpoint.Web.UI.Controls;
using System.IO;

namespace Centralpoint.WebSite.Uploads.SampleControl
{
    public partial class CustomControl : Centralpoint.WebSite.Modules.UserControl
    {
        public string Parameter1 { get; set; } 

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        /// <summary>
        /// This method provides the event handler for the page load event.
        /// </summary>
        /// <param name="e">Set to the event arguments.
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            dvTest.InnerText = String.Format("This is my custom control{0}", 
                String.IsNullOrEmpty(this.Parameter1) ? " with no Parameter1 value." : " with Parameter1 Value=" + this.Parameter1);
        }
    }
}






Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.