/// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                if (CurrentCheckInState != null)
                {
                    string script = string.Format(@"
    <script>
        $(document).ready(function (e) {{
            if (localStorage) {{
                localStorage.theme = '{0}'
                localStorage.checkInKiosk = '{1}';
                localStorage.checkInType = '{2}';
                localStorage.checkInGroupTypes = '{3}';
            }}
        }});
    </script>
", CurrentTheme, CurrentKioskId, CurrentCheckinTypeId, CurrentGroupTypeIds.AsDelimited(","));
                    phScript.Controls.Add(new LiteralControl(script));

                    CurrentWorkflow              = null;
                    CurrentCheckInState.CheckIn  = new CheckInStatus();
                    CurrentCheckInState.Messages = new List <CheckInMessage>();
                    SaveState();

                    string familyId = PageParameter("FamilyId");
                    if (familyId.IsNotNullOrWhiteSpace())
                    {
                        var dv = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_FAMILY_ID);
                        DoFamilySearch(dv, familyId);
                    }
                    else
                    {
                        RefreshView();

                        lNotActiveTitle.Text      = GetAttributeValue("NotActiveTitle");
                        lNotActiveCaption.Text    = GetAttributeValue("NotActiveCaption");
                        lNotActiveYetTitle.Text   = GetAttributeValue("NotActiveYetTitle");
                        lNotActiveYetCaption.Text = string.Format(GetAttributeValue("NotActiveYetCaption"), "<span class='countdown-timer'></span>");
                        lClosedTitle.Text         = GetAttributeValue("ClosedTitle");
                        lClosedCaption.Text       = GetAttributeValue("ClosedCaption");

                        string checkinButtonText = GetAttributeValue("CheckinButtonText").IfEmpty("Start");

                        var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions {
                            GetLegacyGlobalMergeFields = false
                        });
                        mergeFields.Add("CheckinButtonText", checkinButtonText);
                        mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk);
                        mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled);

                        if (CurrentGroupTypeIds != null)
                        {
                            var checkInAreas = CurrentGroupTypeIds.Select(a => GroupTypeCache.Get(a));
                            mergeFields.Add("CheckinAreas", checkInAreas);
                        }

                        lStartButtonHtml.Text = CurrentCheckInState.CheckInType.StartLavaTemplate.ResolveMergeFields(mergeFields);
                    }
                }
            }
            else
            {
                if (Request.Form["__EVENTARGUMENT"] != null)
                {
                    if (Request.Form["__EVENTARGUMENT"] == "Wedge_Entry")
                    {
                        var dv = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_SCANNED_ID);
                        DoFamilySearch(dv, hfSearchEntry.Value);
                    }
                    else if (Request.Form["__EVENTARGUMENT"] == "Family_Id_Search")
                    {
                        var dv = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_FAMILY_ID);
                        DoFamilySearch(dv, hfSearchEntry.Value);
                    }
                    else if (Request.Form["__EVENTARGUMENT"] == "StartClick")
                    {
                        HandleStartClick();
                    }
                }
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (CurrentWorkflow == null || CurrentCheckInState == null)
            {
                NavigateToHomePage();
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    try
                    {
                        lTitle.Text = GetAttributeValue("Title");
                        string detailMsg = GetAttributeValue("DetailMessage");

                        var printFromClient = new List <CheckInLabel>();
                        var printFromServer = new List <CheckInLabel>();

                        List <CheckinResult> checkinResultList = new List <CheckinResult>();

                        // Print the labels
                        foreach (var family in CurrentCheckInState.CheckIn.Families.Where(f => f.Selected))
                        {
                            lbAnother.Visible =
                                CurrentCheckInState.CheckInType.TypeOfCheckin == TypeOfCheckin.Individual &&
                                family.People.Count > 1;

                            foreach (var person in family.GetPeople(true))
                            {
                                foreach (var groupType in person.GetGroupTypes(true))
                                {
                                    foreach (var group in groupType.GetGroups(true))
                                    {
                                        foreach (var location in group.GetLocations(true))
                                        {
                                            foreach (var schedule in location.GetSchedules(true))
                                            {
                                                string        detailMessage = string.Format(detailMsg, person.ToString(), group.ToString(), location.Location.Name, schedule.ToString(), person.SecurityCode);
                                                CheckinResult checkinResult = new CheckinResult();
                                                checkinResult.Person        = person;
                                                checkinResult.Group         = group;
                                                checkinResult.Location      = location.Location;
                                                checkinResult.Schedule      = schedule;
                                                checkinResult.DetailMessage = detailMessage;
                                                checkinResultList.Add(checkinResult);
                                            }
                                        }
                                    }

                                    if (groupType.Labels != null && groupType.Labels.Any())
                                    {
                                        printFromClient.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Client));
                                        printFromServer.AddRange(groupType.Labels.Where(l => l.PrintFrom == Rock.Model.PrintFrom.Server));
                                    }
                                }
                            }
                        }

                        var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions {
                            GetLegacyGlobalMergeFields = false
                        });
                        mergeFields.Add("CheckinResultList", checkinResultList);
                        mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk);
                        mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled);
                        mergeFields.Add("Messages", CurrentCheckInState.Messages);
                        if (CurrentGroupTypeIds != null)
                        {
                            var checkInAreas = CurrentGroupTypeIds.Select(a => Rock.Web.Cache.GroupTypeCache.Get(a));
                            mergeFields.Add("CheckinAreas", checkInAreas);
                        }

                        if (printFromClient.Any())
                        {
                            var urlRoot = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority);
                            printFromClient
                            .OrderBy(l => l.PersonId)
                            .ThenBy(l => l.Order)
                            .ToList()
                            .ForEach(l => l.LabelFile = urlRoot + l.LabelFile);
                            AddLabelScript(printFromClient.ToJson());
                        }

                        if (printFromServer.Any())
                        {
                            var messages = ZebraPrint.PrintLabels(printFromServer);
                            mergeFields.Add("ZebraPrintMessageList", messages);
                        }

                        var successLavaTemplate = CurrentCheckInState.CheckInType.SuccessLavaTemplate;
                        lCheckinResultsHtml.Text = successLavaTemplate.ResolveMergeFields(mergeFields);
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }
            }
        }