Esempio n. 1
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Label lblQuestion = new Label();
            _dpAnswer = new DatePickerControl();
            _dpAnswer.SkinID = "Survey";
            _dpAnswer.Text = _answer;
            RequiredFieldValidator valQuestion = new RequiredFieldValidator();

            lblQuestion.ID = "lbl" + _question.QuestionGuid.ToString().Replace("-", String.Empty); ;
            _dpAnswer.ID = "dp" + _question.QuestionGuid.ToString().Replace("-", String.Empty);
            valQuestion.ID = "val" + _question.QuestionGuid.ToString().Replace("-", String.Empty);

            lblQuestion.Text = _question.QuestionText;
            lblQuestion.AssociatedControlID = _dpAnswer.ID;

            valQuestion.ControlToValidate = _dpAnswer.ID;
            valQuestion.Enabled = _question.AnswerIsRequired;

            valQuestion.Text = _question.ValidationMessage;

            Controls.Add(lblQuestion);
            Controls.Add(_dpAnswer);
            Controls.Add(valQuestion);
        }
        private static DatePickerControl CreateDatePicker(
            mojoProfilePropertyDefinition propertyDefinition,
            String propertyValue,
            Double legacyTimeZoneOffset,
            TimeZoneInfo timeZone,
            string siteRoot)
        {
            DatePickerControl datePicker = new DatePickerControl();
            try
            {
                datePicker.SkinID = propertyDefinition.Name.Replace(" ", string.Empty);
            }
            catch (ArgumentException) { }
            datePicker.ID = "dp" + propertyDefinition.Name;
            datePicker.ShowMonthList = propertyDefinition.DatePickerShowMonthList;
            datePicker.ShowYearList = propertyDefinition.DatePickerShowYearList;
            if (propertyDefinition.DatePickerYearRange.Length > 0)
            {
                datePicker.YearRange = propertyDefinition.DatePickerYearRange;
            }

            if (propertyValue.Length > 0)
            {
                DateTime dt;
                if (DateTime.TryParse(
                    propertyValue,
                    CultureInfo.CurrentCulture,
                    DateTimeStyles.AdjustToUniversal, out dt))
                {

                    if (propertyDefinition.IncludeTimeForDate)
                    {
                        if (timeZone != null)
                        {
                            dt = dt.ToLocalTime(timeZone);
                        }
                        else
                        {
                            dt = dt.AddHours(legacyTimeZoneOffset);
                        }
                        datePicker.Text = dt.ToString("g");

                    }
                    else
                    {
                        datePicker.Text = dt.Date.ToShortDateString();
                    }
                }
                else
                {
                    datePicker.Text = propertyValue;
                }
            }
            else
            {
                if (propertyDefinition.DefaultValue.Length > 0)
                {
                    datePicker.Text = propertyDefinition.DefaultValue;
                }
            }

            datePicker.ShowTime = propertyDefinition.IncludeTimeForDate;

            return datePicker;
        }