/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { this.Controls.Clear(); // Insert our begin marker for the survey control. We can parse this out easy later if needed. this.Controls.Add(new Literal { Text = BeginSurveyMarker }); var mainDiv = new HtmlGenericControl("DIV"); mainDiv.Attributes["class"] = this.CssClass; this.Controls.Add(mainDiv); var ph = new PlaceHolder(); this.Controls.Add(ph); if (this.CurrentSurvey == null) { var nosurveyDiv = new HtmlGenericControl("DIV"); nosurveyDiv.Attributes["class"] = CssClassNoSurveyDefined; return; } string thanks = this.Context.Request.QueryString["thankyou"]; if (thanks == "true") { this.Visible = false; return; } // TODO: switch to UTC dates bool beforeStartDate = this.CurrentSurvey.StartDate > DateTime.Now; bool afterEndDate = this.CurrentSurvey.EndDate <= DateTime.Now; if (beforeStartDate || afterEndDate || this.ShowAlreadyTakenMessage) { string messageHtml; if (this.ShowAlreadyTakenMessage) { messageHtml = this.AlreadyTakenMessage; } else { var message = beforeStartDate ? this.CurrentSurvey.PreStartMessage : this.CurrentSurvey.PostEndMessage; var messageWrapperHtmlFormat = beforeStartDate ? this.PreStartMessageTemplate : this.PostEndMessageTemplate; messageHtml = string.Format(CultureInfo.CurrentCulture, messageWrapperHtmlFormat, HttpUtility.HtmlEncode(message)); } ph.Controls.Add(new Literal { Text = messageHtml }); } else { // Need to make validator construction mechanism as we create new implementations! hk // draw the survey this.CurrentSurvey.Render(ph, this.IsReadOnly, this.ShowRequiredNotation, new EngageValidationProvider(this.ValidationGroup), this.Localizer); // no need to include the submit button in html if (!this.IsReadOnly) { this.RenderSubmitButton(); } if (this.Validators != null) { var validatorsContainer = new ValidatorsTemplateContainer(this.ValidationGroup); this.Validators.InstantiateIn(validatorsContainer); ph.Controls.Add(validatorsContainer); } } this.RenderBackButton(this); this.Controls.Add(new Literal { Text = EndSurveyMarker }); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { this.Controls.Clear(); // Insert our begin marker for the survey control. We can parse this out easy later if needed. this.Controls.Add(new Literal { Text = BeginSurveyMarker }); var mainDiv = new HtmlGenericControl("DIV"); mainDiv.Attributes["class"] = this.CssClass; this.Controls.Add(mainDiv); var ph = new PlaceHolder(); this.Controls.Add(ph); if (this.CurrentSurvey == null) { var nosurveyDiv = new HtmlGenericControl("DIV"); nosurveyDiv.Attributes["class"] = CssClassNoSurveyDefined; return; } string thanks = this.Context.Request.QueryString["thankyou"]; if (thanks == "true") { this.Visible = false; return; } // TODO: switch to UTC dates bool beforeStartDate = this.CurrentSurvey.StartDate > DateTime.Now; bool afterEndDate = this.CurrentSurvey.EndDate <= DateTime.Now; if (beforeStartDate || afterEndDate || this.ShowAlreadyTakenMessage) { string messageHtml; if (this.ShowAlreadyTakenMessage) { messageHtml = this.AlreadyTakenMessage; } else { var message = beforeStartDate ? this.CurrentSurvey.PreStartMessage : this.CurrentSurvey.PostEndMessage; var messageWrapperHtmlFormat = beforeStartDate ? this.PreStartMessageTemplate : this.PostEndMessageTemplate; messageHtml = string.Format(CultureInfo.CurrentCulture, messageWrapperHtmlFormat, HttpUtility.HtmlEncode(message)); } ph.Controls.Add(new Literal { Text = messageHtml }); } else { // Need to make validator construction mechanism as we create new implementations! hk // draw the survey this.CurrentSurvey.Render(ph, this.IsReadOnly, this.ShowRequiredNotation, new EngageValidationProvider(this.ValidationGroup), this.Localizer); // no need to include the submit button in html if (!this.IsReadOnly) { this.RenderSubmitButton(); } if (this.Validators != null) { var validatorsContainer = new ValidatorsTemplateContainer(this.ValidationGroup); this.Validators.InstantiateIn(validatorsContainer); ph.Controls.Add(validatorsContainer); } } this.RenderBackButton(this); this.Controls.Add(new Literal { Text = EndSurveyMarker }); }