using System; using System.Web.UI; using CMS.EventLog; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.ExtendedControls; public partial class CMSWebParts_General_usercontrol : CMSAbstractWebPart { private string mUserControlPath = ""; /// /// Gets or sets the path of the user control. /// public string UserControlPath { get { return ValidationHelper.GetString(GetValue("UserControlPath"), mUserControlPath); } set { SetValue("UserControlPath", value); mUserControlPath = value; } } /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do not process } else { } } /// /// Loads the user control. /// protected void LoadUserControl() { if (!string.IsNullOrEmpty(UserControlPath)) { try { Control ctrl = Page.LoadUserControl(UserControlPath); ctrl.ID = "userControlElem"; Controls.Add(ctrl); } catch (Exception ex) { lblError.Text = "[" + ID + "] " + GetString("WebPartUserControl.ErrorLoad") + ": " + ex.Message; lblError.ToolTip = EventLogProvider.GetExceptionLogMessage(ex); lblError.Visible = true; } } } protected override void OnInit(EventArgs e) { base.OnInit(e); // The control must load after OnInit to properly load its viewstate this.LoadUserControl(); } }