Files
VAR.WebFormsCore/VAR.Focus.Web/Pages/FormUtils.cs

83 lines
2.4 KiB
C#

using System.Web.UI;
using System.Web.UI.WebControls;
using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages
{
public class FormUtils
{
public static Control CreatePanel(Control ctrl, string cssClass)
{
Panel pnl = new Panel();
pnl.Controls.Add(ctrl);
if (string.IsNullOrEmpty(cssClass) == false)
{
pnl.CssClass = cssClass;
}
return pnl;
}
public static Control CreatePanel(Control ctrl)
{
return CreatePanel(ctrl, null);
}
public static Control CreateField(string label, Control fieldControl)
{
Panel pnlRow = new Panel();
pnlRow.CssClass = "formRow";
Panel pnlLabelContainer = new Panel();
pnlLabelContainer.CssClass = "formLabel width25pc";
pnlRow.Controls.Add(pnlLabelContainer);
if (string.IsNullOrEmpty(label) == false)
{
CLabel lblField = new CLabel();
lblField.Text = label;
pnlLabelContainer.Controls.Add(lblField);
}
Panel pnlFieldContainer = new Panel();
pnlFieldContainer.CssClass = "formField width75pc";
pnlRow.Controls.Add(pnlFieldContainer);
pnlFieldContainer.Controls.Add(fieldControl);
return pnlRow;
}
public static bool Control_IsValid(Control control)
{
if (control is IValidableControl)
{
if (((IValidableControl)control).IsValid() == false)
{
return false;
}
}
return true;
}
public static bool Controls_AreValid(ControlCollection controls) {
bool valid = true;
foreach (Control control in controls)
{
if (Control_IsValid(control))
{
if (Controls_AreValid(control.Controls) == false)
{
valid = false;
break;
}
}
else
{
valid = false;
break;
}
}
return valid;
}
}
}