/// <include file='doc\ChtmlCalendarAdapter.uex' path='docs/doc[@for="ChtmlCalendarAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            ArrayList          arr;
            DateTime           tempDate;
            DateTimeFormatInfo currentDateTimeInfo        = DateTimeFormatInfo.CurrentInfo;
            String             abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern);

            _threadCalendar = currentDateTimeInfo.Calendar;
            bool breakAfter = false;

            writer.EnterStyle(Style);

            Debug.Assert(NotSecondaryUI == NotSecondaryUIInit);
            switch (SecondaryUIMode)
            {
            case FirstPrompt:
                String promptText = Control.CalendarEntryText;
                if (String.IsNullOrEmpty(promptText))
                {
                    promptText = SR.GetString(SR.CalendarAdapterFirstPrompt);
                }

                // Link to input option selection screen
                RenderPostBackEventAsAnchor(writer,
                                            OptionPrompt.ToString(CultureInfo.InvariantCulture),
                                            promptText);

                // We should honor BreakAfter property here as the first
                // UI is shown with other controls on the same form.
                // For other secondary UI, it is not necessary.
                if (Control.BreakAfter)
                {
                    breakAfter = true;
                }
                break;

            // Render the first secondary page that provides differnt
            // options to select a date.
            case OptionPrompt:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionPrompt));
                writer.WriteBreak();

                arr = new ArrayList();

                // Option to select the default date
                arr.Add(Control.VisibleDate.ToString(
                            currentDateTimeInfo.ShortDatePattern, CultureInfo.CurrentCulture));

                // Option to another page that can enter a date by typing
                arr.Add(SR.GetString(SR.CalendarAdapterOptionType));

                // Options to a set of pages for selecting a date, a week
                // or a month by picking month/year, week and day
                // accordingly.  Available options are determined by
                // SelectionMode.
                arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseDate));

                if (Control.SelectionMode == CalendarSelectionMode.DayWeek ||
                    Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                {
                    arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseWeek));

                    if (Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                    {
                        arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    }
                }

                DataBindAndRender(writer, _optionList, arr);
                break;

            // Render a title and textbox to capture a date entered by user
            case TypeDate:
                if (_textBoxErrorMessage != null)
                {
                    writer.Write(_textBoxErrorMessage);
                    writer.WriteBreak();
                }

                if (_selectList.Visible)
                {
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionEra));
                    writer.WriteBreak();
                    _selectList.RenderControl(writer);
                }

                String numericDateFormat = GetNumericDateFormat();

                writer.Write(SR.GetString(SR.CalendarAdapterOptionType));
                writer.Write(":");
                writer.WriteBreak();
                writer.Write("(");
                writer.Write(numericDateFormat.ToUpper(CultureInfo.InvariantCulture));
                writer.Write(")");

                if (!_selectList.Visible)
                {
                    writer.Write(GetEra(Control.VisibleDate));
                }
                writer.WriteBreak();

                _textBox.Numeric   = true;
                _textBox.Size      = numericDateFormat.Length;
                _textBox.MaxLength = numericDateFormat.Length;
                _textBox.Text      = Control.VisibleDate.ToString(numericDateFormat, CultureInfo.InvariantCulture);
                _textBox.Visible   = true;
                _textBox.RenderControl(writer);

                // Command button for sending the textbox value back to the server
                _command.Text    = GetDefaultLabel(OKLabel);
                _command.Visible = true;
                _command.RenderControl(writer);

                break;

            // Render a paged list for choosing a month
            case ChooseMonth:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                writer.Write(":");
                writer.WriteBreak();

                tempDate = Control.VisibleDate;

                String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern);

                // This is to be consistent with ASP.NET Calendar control
                // on handling YearMonthPattern:
                // Some cultures have a comma in their YearMonthPattern,
                // which does not look right in a calendar.  Here we
                // strip the comma off.
                int indexComma = abbreviatedYearMonthPattern.IndexOf(',');
                if (indexComma >= 0)
                {
                    abbreviatedYearMonthPattern =
                        abbreviatedYearMonthPattern.Remove(indexComma, 1);
                }

                arr = new ArrayList();
                for (int i = 0; i < _monthsToDisplay; i++)
                {
                    arr.Add(tempDate.ToString(abbreviatedYearMonthPattern, CultureInfo.CurrentCulture));
                    tempDate = _threadCalendar.AddMonths(tempDate, 1);
                }
                arr.Add(GetDefaultLabel(NextLabel));
                arr.Add(GetDefaultLabel(PreviousLabel));

                DataBindAndRender(writer, _monthList, arr);
                break;

            // Based on the month selected in case ChooseMonth above, render a list of
            // availabe weeks of the month.
            case ChooseWeek:
                String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy";
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseWeek));
                writer.Write(" (");
                writer.Write(Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture));
                writer.Write("):");
                writer.WriteBreak();

                // List weeks of days of the selected month.  May include
                // days from the previous and the next month to fill out
                // all six week choices.  This is consistent with the
                // ASP.NET Calendar control.

                // Note that the event handling code of this list control
                // should be implemented according to the index content
                // generated here.

                tempDate = FirstCalendarDay(Control.VisibleDate);

                arr = new ArrayList();
                String weekDisplay;
                for (int i = 0; i < 6; i++)
                {
                    weekDisplay  = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                    weekDisplay += DaySeparator;
                    tempDate     = _threadCalendar.AddDays(tempDate, 6);
                    weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                    arr.Add(weekDisplay);
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }

                DataBindAndRender(writer, _weekList, arr);
                break;

            // Based on the month and week selected in case ChooseMonth and ChooseWeek above,
            // render a list of the dates in the week.
            case ChooseDay:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseDate));
                writer.Write(":");
                writer.WriteBreak();

                tempDate = Control.VisibleDate;

                arr = new ArrayList();
                String        date;
                String        dayName;
                StringBuilder dayDisplay   = new StringBuilder();
                bool          dayNameFirst = (GetNumericDateFormat()[0] != 'y');

                for (int i = 0; i < 7; i++)
                {
                    date = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);

                    if (Control.ShowDayHeader)
                    {
                        // Use the short format for displaying day name
                        dayName           = GetAbbreviatedDayName(tempDate);
                        dayDisplay.Length = 0;

                        if (dayNameFirst)
                        {
                            dayDisplay.Append(dayName);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(date);
                        }
                        else
                        {
                            dayDisplay.Append(date);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(dayName);
                        }
                        arr.Add(dayDisplay.ToString());
                    }
                    else
                    {
                        arr.Add(date);
                    }
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }

                DataBindAndRender(writer, _dayList, arr);
                break;

            default:
                Debug.Assert(false, "Unexpected Secondary UI Mode");
                break;
            }

            writer.ExitStyle(Style, breakAfter);
        }
        public override void Render(WmlMobileTextWriter writer)
        {
            ArrayList          arr;
            DateTime           tempDate;
            DateTimeFormatInfo currentDateTimeInfo        = DateTimeFormatInfo.CurrentInfo;
            String             abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern);

            _threadCalendar = currentDateTimeInfo.Calendar;

            // RendersWmlSelectsAsMenuCards is true means the list control will be
            // rendered as select/option tags, where the break tag before
            // them will become an extra line which doesn't like good.
            bool addBreakBeforeListControl = Device.RendersWmlSelectsAsMenuCards;

            writer.EnterStyle(Style);

            Debug.Assert(NotSecondaryUI == NotSecondaryUIInit);
            switch (SecondaryUIMode)
            {
            case FirstPrompt:
                String promptText = Control.CalendarEntryText;
                if (promptText == String.Empty)
                {
                    promptText = SR.GetString(SR.CalendarAdapterFirstPrompt);
                }

                // Link to input option selection screen
                RenderPostBackEvent(writer,
                                    OptionPrompt.ToString(),
                                    GetDefaultLabel(GoLabel),
                                    true,
                                    promptText,
                                    true);
                break;

            // Render the first secondary page that provides differnt
            // options to select a date.
            case OptionPrompt:
                writer.RenderText(SR.GetString(SR.CalendarAdapterOptionPrompt),
                                  !addBreakBeforeListControl);

                arr = new ArrayList();

                // Option to select the default date
                arr.Add(Control.VisibleDate.ToString(
                            currentDateTimeInfo.ShortDatePattern));

                // Option to another page that can enter a date by typing
                arr.Add(SR.GetString(SR.CalendarAdapterOptionType));

                // Options to a set of pages for selecting a date, a week
                // or a month by picking month/year, week and day
                // accordingly.  Available options are determined by
                // SelectionMode.
                arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseDate));

                if (Control.SelectionMode == CalendarSelectionMode.DayWeek ||
                    Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                {
                    arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseWeek));

                    if (Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                    {
                        arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    }
                }
                DataBindAndRender(writer, _optionList, arr);
                break;

            // Render a title and textbox to capture a date entered by user
            case TypeDate:
                if (_textBoxErrorMessage != null)
                {
                    writer.RenderText(_textBoxErrorMessage, true);
                }

                if (_selectList.Visible)
                {
                    writer.RenderText(SR.GetString(SR.CalendarAdapterOptionEra), true);
                    _selectList.RenderControl(writer);
                }

                String numericDateFormat = GetNumericDateFormat();

                writer.RenderText(SR.GetString(SR.CalendarAdapterOptionType) + ":", true);
                writer.RenderText("(");
                writer.RenderText(numericDateFormat.ToUpper());
                writer.RenderText(")");

                if (!_selectList.Visible)
                {
                    writer.RenderText(GetEra(Control.VisibleDate));
                }
                writer.RenderText(String.Empty, true);

                _textBox.Numeric   = true;
                _textBox.Size      = numericDateFormat.Length;
                _textBox.MaxLength = numericDateFormat.Length;
                _textBox.Text      = Control.VisibleDate.ToString(numericDateFormat);
                _textBox.Visible   = true;
                _textBox.RenderControl(writer);

                String okLabel = GetDefaultLabel(OKLabel);

                // accept softkey for sending the textbox value back to the server
                RenderPostBackEvent(writer,
                                    TypeDateDone.ToString(),
                                    okLabel,
                                    true,
                                    okLabel,
                                    true,
                                    WmlPostFieldType.Raw);
                break;

            // Render a paged list for choosing a month
            case ChooseMonth:
            {
                String displayText = String.Format("{0}:", SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                writer.RenderText(displayText, !addBreakBeforeListControl);

                tempDate = Control.VisibleDate;

                String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern);

                // This is to be consistent with ASP.NET Calendar control
                // on handling YearMonthPattern:
                // Some cultures have a comma in their YearMonthPattern,
                // which does not look right in a calendar.  Here we
                // strip the comma off.
                int indexComma = abbreviatedYearMonthPattern.IndexOf(',');
                if (indexComma >= 0)
                {
                    abbreviatedYearMonthPattern =
                        abbreviatedYearMonthPattern.Remove(indexComma, 1);
                }

                arr = new ArrayList();
                for (int i = 0; i < _monthsToDisplay; i++)
                {
                    arr.Add(tempDate.ToString(abbreviatedYearMonthPattern));
                    tempDate = _threadCalendar.AddMonths(tempDate, 1);
                }
                arr.Add(GetDefaultLabel(NextLabel));
                arr.Add(GetDefaultLabel(PreviousLabel));
                DataBindAndRender(writer, _monthList, arr);
                break;
            }

            // Based on the month selected in case ChooseMonth above, render a list of
            // availabe weeks of the month.
            case ChooseWeek:
            {
                String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy";
                String displayText = String.Format("{0} ({1}):",
                                                   SR.GetString(SR.CalendarAdapterOptionChooseWeek),
                                                   Control.VisibleDate.ToString(monthFormat));
                writer.RenderText(displayText, !addBreakBeforeListControl);

                // List weeks of days of the selected month.  May include
                // days from the previous and the next month to fill out
                // all six week choices.  This is consistent with the
                // ASP.NET Calendar control.

                // Note that the event handling code of this list control
                // should be implemented according to the index content
                // generated here.

                tempDate = FirstCalendarDay(Control.VisibleDate);

                arr = new ArrayList();
                String weekDisplay;
                for (int i = 0; i < 6; i++)
                {
                    weekDisplay  = tempDate.ToString(abbreviatedMonthDayPattern);
                    weekDisplay += DaySeparator;
                    tempDate     = _threadCalendar.AddDays(tempDate, 6);
                    weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern);
                    arr.Add(weekDisplay);
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }
                DataBindAndRender(writer, _weekList, arr);
                break;
            }

            // Based on the month and week selected in case ChooseMonth and ChooseWeek above,
            // render a list of the dates in the week.
            case ChooseDay:
            {
                String displayText = String.Format("{0}:", SR.GetString(SR.CalendarAdapterOptionChooseDate));
                writer.RenderText(displayText, !addBreakBeforeListControl);

                tempDate = Control.VisibleDate;

                arr = new ArrayList();
                String        date;
                String        dayName;
                StringBuilder dayDisplay   = new StringBuilder();
                bool          dayNameFirst = (GetNumericDateFormat()[0] != 'y');

                for (int i = 0; i < 7; i++)
                {
                    date = tempDate.ToString(abbreviatedMonthDayPattern);

                    if (Control.ShowDayHeader)
                    {
                        // Use the short format for displaying day name
                        dayName           = GetAbbreviatedDayName(tempDate);
                        dayDisplay.Length = 0;

                        if (dayNameFirst)
                        {
                            dayDisplay.Append(dayName);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(date);
                        }
                        else
                        {
                            dayDisplay.Append(date);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(dayName);
                        }
                        arr.Add(dayDisplay.ToString());
                    }
                    else
                    {
                        arr.Add(date);
                    }
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }
                DataBindAndRender(writer, _dayList, arr);
                break;
            }

            default:
                Debug.Assert(false, "Unexpected Secondary UI Mode");
                break;
            }
            writer.ExitStyle(Style);
        }