Example #1
0
        protected override void OnInit(EventArgs e)
        {
            var units = WebManager.GetUnits();

            foreach (WebUnitGroup webUnitGroup in _webManager.WebUnitGroups)
            {
                if (webUnitGroup.Enabled == false)
                {
                    continue;
                }

                // add a Unit Group (e.g. "Length", "Area") to the page

                UnitGroupControl unitGroupControl = (UnitGroupControl)Page.LoadControl("~/UnitGroupControl.ascx");
                unitGroupControl.Initialize(webUnitGroup);

                // add all enabled Units (e.g. "Meter", "Yard") to the Unit Group control

                foreach (WebUnit webUnit in _webManager.WebUnits)
                {
                    if (webUnit.Enabled)
                    {
                        var unit = units.First(p => p.ID == webUnit.UnitID);

                        if (unit.Type == webUnitGroup.UnitType)
                        {
                            UnitControl unitControl = (UnitControl)Page.LoadControl("~/UnitControl.ascx");
                            unitControl.Initialize(webUnit);
                            unitGroupControl.AddUnitControl(unitControl);
                        }
                    }
                }

                UnitGroupsPlaceHolder.Controls.Add(unitGroupControl);
            }
        }
 /// <summary>
 /// Adds a UnitControl element to the placeholder in the unit group.
 /// </summary>
 /// <param name="control"></param>
 public void AddUnitControl(UnitControl control)
 {
     UnitControlPlaceHolder.Controls.Add(control);
 }