protected override void OnStart(TextWriter writer)
        {
            Prepare(writer);

            if (Checked)
            {
                MergeAttribute("checked", "checked");
            }

            // Add the description as child content
            if (!string.IsNullOrEmpty(Description))
            {
                AddChild(GetHelper().Content(" " + Description));
            }
            else if (Inline && !SuppressLabelWrapper)
            {
                // Add a space if we're inline without a description
                // This counters the problem of non-labeled checked controls when inline not positioning properly
                // From Bootstrap docs: "Currently only works on non-inline checkboxes and radios."
                AddChild(GetHelper().Content(" "));
            }

            // See if we're in a horizontal form or form group
            Form      form       = GetComponent <Form>();
            FormGroup formGroup  = GetComponent <FormGroup>();
            bool      horizontal = form != null && form.Horizontal && (formGroup == null || !formGroup.Horizontal.HasValue || formGroup.Horizontal.Value);

            // Add the wrapper
            if (!Inline)
            {
                ComponentBuilder <BootstrapConfig, Element> builder = GetHelper().Element("div").AddCss(GetAttribute("type"));

                // Hack to make manual padding adjustments if we're horizontal
                if (horizontal)
                {
                    builder.AddStyle("padding-top", "0");
                }

                _wrapper = builder.Component;
                _wrapper.Start(writer);
            }

            // Add the label wrapper
            if (!SuppressLabelWrapper)
            {
                ComponentBuilder <BootstrapConfig, Element> labelBuilder = GetHelper().Element("label").AddCss(Inline ? GetAttribute("type") + "-inline" : GetAttribute("type"));

                // Another hack for manual padding adjustments if inline and horizontal
                if (Inline && horizontal)
                {
                    labelBuilder.AddStyle("padding-top", "0");
                }

                _label = labelBuilder.Component;
                _label.Start(writer);
            }

            base.OnStart(writer);
        }
        // This prepares the outer form group if we need one
        // Needs to be in a separate method so that derived classes can create the form group before outputting any wrappers of their own
        protected void Prepare(TextWriter writer)
        {
            // Only prepare once
            if (_prepared)
            {
                return;
            }
            _prepared = true;

            // Make sure we're in a form group
            IFormGroup formGroup = GetComponent <IFormGroup>();

            if (formGroup == null && EnsureFormGroup)
            {
                _formGroup = new FormGroup <THelper>(Helper);
                formGroup  = _formGroup;
            }

            // Move any validation classes to the form group, but only if it's implicit for this control and doesn't already have any
            if (CssClasses.Any(x => x.StartsWith("has-")) && _formGroup != null && formGroup != null && !formGroup.CssClasses.Any(x => x.StartsWith("has-")))
            {
                foreach (string formValidation in CssClasses.Where(x => x.StartsWith("has-")))
                {
                    formGroup.CssClasses.Add(formValidation);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("has-"));
            }

            // Move any grid column classes to the form group, but only if it's implicit for this control and doesn't already have any
            if (CssClasses.Any(x => x.StartsWith("col-")) && _formGroup != null && formGroup != null && !formGroup.CssClasses.Any(x => x.StartsWith("col-")))
            {
                foreach (string col in CssClasses.Where(x => x.StartsWith("col-")))
                {
                    formGroup.CssClasses.Add(col);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("col-"));
            }

            // Add the label to the form group or write it
            if (_label != null)
            {
                // Set the label's for attribute to the input name
                string name = Attributes.GetValue("name");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    _label.MergeAttribute("for", name);
                }

                // Add or write the label
                if (_formGroup != null)
                {
                    _formGroup.ControlLabel = _label;
                }
                else
                {
                    _label.StartAndFinish(writer);
                }
            }

            // Start the new form group if we created one
            if (_formGroup != null)
            {
                _formGroup.Start(writer);
            }

            _prepared = true;
        }
        // This prepares the outer form group if we need one
        // Needs to be in a separate method so that derived classes can create the form group before outputting any wrappers of their own
        public void Prepare(TextWriter writer)
        {
            // Only prepare once
            if (_prepared)
            {
                return;
            }
            _prepared = true;

            // Make sure we're in a form group, but only if we're also in a form
            FormGroup formGroup = null;

            if (GetComponent <Form>() != null && GetComponent <FormGroup>() == null && EnsureFormGroup)
            {
                formGroup = new FormGroup(GetHelper());
                _wrapper  = formGroup;
            }

            // Move any validation classes to the wrapper
            if (CssClasses.Any(x => x.StartsWith("has-")))
            {
                if (_wrapper == null)
                {
                    _wrapper = GetHelper().Element("div").Component;
                }
                foreach (string formValidation in CssClasses.Where(x => x.StartsWith("has-")))
                {
                    _wrapper.CssClasses.Add(formValidation);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("has-"));
            }

            // Move any grid column classes to the wrapper
            if (CssClasses.Any(x => x.StartsWith("col-")))
            {
                if (_wrapper == null)
                {
                    _wrapper = GetHelper().Element("div").Component;
                }
                foreach (string col in CssClasses.Where(x => x.StartsWith("col-")))
                {
                    _wrapper.CssClasses.Add(col);
                }
                CssClasses.RemoveWhere(x => x.StartsWith("col-"));
            }

            // Add the label to the form group or write it
            if (_label != null)
            {
                // Set the label's for attribute to the input name
                string name = Attributes.GetValue("name");
                if (!string.IsNullOrWhiteSpace(name))
                {
                    _label.MergeAttribute("for", name);
                }

                // Add or write the label
                if (formGroup != null)
                {
                    formGroup.ControlLabel = _label;
                }
                else
                {
                    _label.StartAndFinish(writer);
                }
            }

            // Start the new form group if we created one
            if (_wrapper != null)
            {
                _wrapper.Start(writer);
            }

            _prepared = true;
        }