Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

96 lines
3.2 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="WmlValidationSummaryAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#if WMLSUPPORT
namespace System.Web.UI.WebControls.Adapters {
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.Util;
public class WmlValidationSummaryAdapter : ValidationSummaryAdapter {
private BulletedList bulletedList;
private bool singleParagraph = false;
protected internal override void OnInit(EventArgs e) {
bulletedList = new BulletedList();
Control.Controls.Add(bulletedList);
}
protected internal override void Render(HtmlTextWriter markupWriter) {
WmlTextWriter writer = (WmlTextWriter)markupWriter;
String[] errorMessages = null;
bool inError = false;
bool enteredStyle = false;
if (!Control.Enabled || !Control.Visible || !Control.ShowSummary) {
return;
}
errorMessages = Control.GetErrorMessages(out inError);
if (!inError) {
return;
}
if (Control.DisplayMode == ValidationSummaryDisplayMode.SingleParagraph) {
singleParagraph = true;
}
if (Control.HeaderText.Length > 0) {
writer.EnterStyle(Control.ControlStyle);
enteredStyle = true;
writer.WriteEncodedText(Control.HeaderText);
WriteSeparator(writer);
}
if (!String.IsNullOrEmpty(errorMessages)) {
if (!enteredStyle) {
writer.EnterStyle(Control.ControlStyle);
enteredStyle = true;
}
if (singleParagraph) {
foreach (String errorMessage in errorMessages) {
Debug.Assert(errorMessage != null && errorMessage.Length > 0, "Bad Error Messages");
writer.WriteEncodedText(errorMessage);
WriteSeparator(writer);
}
writer.WriteBreak();
}
else {
ArrayList arr = new ArrayList();
foreach (String errorMessage in errorMessages) {
Debug.Assert(errorMessage != null && errorMessage.Length > 0, "Bad Error Messages");
arr.Add(errorMessage);
}
bulletedList.DisplayMode = BulletedListDisplayMode.Text;
bulletedList.DataSource = arr;
bulletedList.DataBind();
RenderChildren(writer);
}
}
if (enteredStyle) {
writer.ExitStyle(Control.ControlStyle);
}
}
private void WriteSeparator(HtmlTextWriter writer) {
if (singleParagraph) {
writer.Write(" ");
}
else {
writer.WriteBreak();
}
}
}
}
#endif