Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Ektron – Widget Form

Posted on March 5, 2014October 26, 2015 By David Kittell

In the recent upgrade from Ektron 8.0.2 to 8.7 I’ve been rebuilding forms to user controls that can be used as widgets.

Below is basic elements to make the form work for your Ektron 8.7 (possibly higher).

Please note the TextBox SubmissionEmail, this allows you to change the email address that the form goes to without having to get into the code.

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

<asp:MultiView ID="ViewSet" runat="server" ActiveViewIndex="0">
	<asp:View ID="View" runat="server">
		<asp:Label ID="lblSubmissionEmail" runat="server" Visible="false"></asp:Label>
		<asp:Label ID="labelErrors" CssClass="jobText" runat="server" Style="color: #81060C;" Visible="false"></asp:Label>
		<asp:Literal ID="litThanks" runat="server" Visible="false">
			Your form has been recieved, thank you for your time.<br />
			<a href="<URL of form>">Click here to complete a new form.</a>
		</asp:Literal>
		<div id="divForm" class="contact" runat="server">
			<asp:Label ID="lblProviderName" runat="server" Text="Provider Name"></asp:Label>
			<asp:TextBox ID="txtProviderName" runat="server"></asp:TextBox>
			<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
		</div>
	</asp:View>
	<asp:View ID="Edit" runat="server">
		<div id="<%=ClientID%>_edit">
			<asp:TextBox ID="SubmissionEmail" runat="server" Style="width: 95%" placeholder="Submission Email Address"> </asp:TextBox>
			<asp:Button ID="CancelButton" runat="server" Text="Cancel" OnClick="CancelButton_Click" />
			&nbsp;&nbsp;
			<asp:Button ID="SaveButton" runat="server" Text="Save" OnClick="SaveButton_Click" />
		</div>
	</asp:View>
</asp:MultiView>
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Ektron.Cms.Widget;
using Ektron.Cms;
using Ektron.Cms.API;
using Ektron.Cms.Common;
using Ektron.Cms.PageBuilder;
using System.Configuration;
using System.Data.SqlClient;
using System.Net.Mail;

public partial class codebehindclass : System.Web.UI.UserControl, IWidget
{
	public static string connstring = ConfigurationManager.ConnectionStrings["<Web.config Connection String>"].ToString();
	#region properties
	private string _sSubmissionEmail;
	[WidgetDataMember("Form")]
	public string sSubmissionEmail { get { return _sSubmissionEmail; } set { _sSubmissionEmail = value; } }
	#endregion

	IWidgetHost _host;
	protected ContentAPI m_refContentApi = new ContentAPI();
	protected EkMessageHelper m_refMsg;

	protected void Page_Init(object sender, EventArgs e)
	{
		string sitepath = new CommonApi().SitePath;
		JS.RegisterJSInclude(this, JS.ManagedScript.EktronJS);
		JS.RegisterJSInclude(this, JS.ManagedScript.EktronModalJS);
		Css.RegisterCss(this, Css.ManagedStyleSheet.EktronModalCss);
		_host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
		m_refMsg = m_refContentApi.EkMsgRef;
		_host.Title = "Submission Email";
		_host.Edit += new EditDelegate(EditEvent);
		_host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
		_host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
		_host.Create += new CreateDelegate(delegate() { EditEvent(""); });
		CancelButton.Text = m_refMsg.GetMessage("btn cancel");
		SaveButton.Text = m_refMsg.GetMessage("btn save");
		PreRender += new EventHandler(delegate(object PreRenderSender, EventArgs Evt) { SetOutput(); });
		string myPath = string.Empty;

		ViewSet.SetActiveView(View);
	}

	void EditEvent(string settings)
	{
		SubmissionEmail.Text = sSubmissionEmail;
		ViewSet.SetActiveView(Edit);
	}

	protected void SaveButton_Click(object sender, EventArgs e)
	{
		sSubmissionEmail = SubmissionEmail.Text;
		_host.SaveWidgetDataMembers();
		ViewSet.SetActiveView(View);
	}

	protected void SetOutput()
	{
		lblSubmissionEmail.Text = sSubmissionEmail;
	}

	protected void CancelButton_Click(object sender, EventArgs e)
	{
		ViewSet.SetActiveView(View);
	}

	protected void btnSubmit_Click(object sender, EventArgs e)
	{
		if (ValidateForm())
		{
			string sSQL = "INSERT INTO <tablename>([SubmissionDateTime] " +
			",[ProviderName]) VALUES (@SubmissionDateTime" +
			",@ProviderName)";

			try
			{
				SqlConnection Conn = new SqlConnection(connstring);
				Conn.Open();
				SqlCommand cmd = new SqlCommand(sSQL + " SELECT CAST(scope_identity() AS int)", Conn);

				cmd.Parameters.AddWithValue("@SubmissionDateTime", DateTime.Now.ToString());
				cmd.Parameters.AddWithValue("@ProviderName", txtProviderName.Text);

				int NewRecord = (int)cmd.ExecuteScalar();
				Conn.Close();

				#region Development Email
				MailMessage message = new MailMessage("<Send From Email>", sSubmissionEmail);
				SmtpClient smtpClient = new SmtpClient();
				smtpClient.Port = 25;
				smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
				smtpClient.UseDefaultCredentials = false;
				smtpClient.Host = "<SMTP Server>";
				message.Subject = "<Email Subject> - " + NewRecord.ToString();
				message.Body = "A new form has been submitted";
				#endregion

				//SmtpHelper.CreateSmtpClient().Send(message);
				try
				{
					smtpClient.Send(message);
					divForm.Visible = false;
					litThanks.Visible = true;
				}
				catch (Exception ex)
				{
					labelErrors.Visible = true;
					labelErrors.Text = "Mail Problem: " + Environment.NewLine + ex.Message.ToString();
				}

			}

			catch (Exception ex)
			{
				Response.Write(ex.Message.ToString() + "<br/>");
				Response.End();
			}
		}
		if (labelErrors.Visible)
			labelErrors.Text += "<br /><br />";
	}

	public bool ValidateForm()
	{
		if (!ValidateNotBlank(txtProviderName, "Provider Name", labelErrors)) return false;

		labelErrors.Visible = false;
		return true;
	}

	protected bool ValidateNotBlank(System.Web.UI.WebControls.TextBox control, string message, System.Web.UI.WebControls.Label labelErrors)
	{
		if (control.Text.Trim() == string.Empty)
		{
			labelErrors.Visible = true;
			labelErrors.Text = "The " + message + " field is required, please complete the information.";
			return false;
		}
		return true;
	}
}
Originally Posted on March 5, 2014
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

C# ASPX C# Ektron Code CSharp Ektron

Post navigation

Previous post
Next post

Related Posts

Apple macOS Server – Reset

Posted on September 30, 2017

If you’ve ran into a road block and need to reset the database and everything makes the profile manager work the scripts below will help. I have had to do this personally after removing a device from profile manager and tried to add it again. NOTE: You will need to…

Read More

Get Folder Size

Posted on December 14, 2013October 26, 2015

Function GetFolderSize(ByVal DirPath As String, _ Optional ByVal IncludeSubFolders As Boolean = True) As Long Dim lngDirSize As Long Dim objFileInfo As FileInfo Dim objDir As DirectoryInfo = New DirectoryInfo(DirPath) Dim objSubFolder As DirectoryInfo Try ‘add length of each file For Each objFileInfo In objDir.GetFiles() lngDirSize += objFileInfo.Length Next ‘call…

Read More

Red Hat / CentOS / Fedora – Fix Yum Duplicates

Posted on May 16, 2017May 18, 2017

When nothing else seemed to work this helped me to get rid of all the duplicates from failed yum updates. yum update glibc -t –skip-broken package-cleanup –dupes –skip-broken package-cleanup –cleandupes –skip-broken updatedb sudo yum clean packages –skip-broken sudo yum clean headers –skip-broken sudo yum clean dbcache –skip-broken sudo yum clean…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes