/// <summary> /// Renders the specified ph. /// </summary> /// <param name="section">The section.</param> /// <param name="ph">The placeholder container.</param> /// <param name="readOnly">if set to <c>true</c> [read only].</param> /// <param name="showRequiredNotation">if set to <c>true</c> [show required notation].</param> /// <param name="validationProvider">The validation provider.</param> /// <param name="localizer">Localizes text.</param> public static void RenderSection(ISection section, PlaceHolder ph, bool readOnly, bool showRequiredNotation, ValidationProviderBase validationProvider, ILocalizer localizer) { var sectionDiv = new HtmlGenericControl("DIV"); sectionDiv.Attributes["class"] = Engage.Survey.Util.Utility.CssClassSectionWrap + " section" + section.SectionId; ph.Controls.Add(sectionDiv); // row for the section text var title = new HtmlGenericControl("h3"); title.Attributes["class"] = Engage.Survey.Util.Utility.CssClassSectionTitle; title.InnerHtml = HttpUtility.HtmlEncode(section.FormattedText).Replace("\n", "<br />"); sectionDiv.Controls.Add(title); foreach (IQuestion question in section.GetQuestions()) { // create the question wrap div. var questionWrapDiv = new HtmlGenericControl("DIV"); questionWrapDiv.Attributes["class"] = "qw" + question.QuestionId; sectionDiv.Controls.Add(questionWrapDiv); // create the question span with label in it for question text. var questionSpan = new HtmlGenericControl("SPAN"); questionSpan.Attributes["class"] = Engage.Survey.Util.Utility.CssClassQuestion; questionSpan.InnerHtml = question.FormattedText; questionWrapDiv.Controls.Add(questionSpan); // <span class="questin">Phone<span>*</span></span> // if the question is required, then add the optional * notation. if (question.IsRequired && showRequiredNotation) { var requiredSpan = new HtmlGenericControl("SPAN"); requiredSpan.Attributes["class"] = Engage.Survey.Util.Utility.CssClassRequired; requiredSpan.InnerText = localizer.Localize("RequiredNotation.Text"); questionSpan.Controls.Add(requiredSpan); } // Create a span to put answer(s) in. Control control = Engage.Survey.Util.Utility.CreateWebControl(question, readOnly, string.Empty, localizer); questionWrapDiv.Controls.Add(control); if (string.IsNullOrEmpty(control.ID) || validationProvider == null) { continue; } // TODO: Localize error messages if (question.IsRequired && question.ControlType != ControlType.Checkbox) { validationProvider.RegisterValidator(ph.Page.ClientScript, ValidationType.RequiredField, "error-message", questionWrapDiv, control.ID, string.Format(localizer.Localize("RequiredError.Format"), question.UnformattedText), 1, 0); } switch (question.ControlType) { case ControlType.LargeTextInputField: case ControlType.SmallTextInputField: validationProvider.RegisterValidator(ph.Page.ClientScript, ValidationType.LimitedLengthField, "error-message", questionWrapDiv, control.ID, string.Format(localizer.Localize("TextLengthExceeded.Format"), question.UnformattedText), 1, 4000); break; case ControlType.EmailInputField: validationProvider.RegisterValidator(ph.Page.ClientScript, ValidationType.EmailField, "error-message", questionWrapDiv, control.ID, localizer.Localize("InvalidEmail.Text"), 1, 0); break; case ControlType.Checkbox: validationProvider.RegisterValidator(ph.Page.ClientScript, ValidationType.LimitedSelection, "error-message", questionWrapDiv, control.ID, string.Empty, question.SelectionLimit, 0); break; } } }