Basic form validation.
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Web.UI.WebControls;
|
|||||||
|
|
||||||
namespace Scrummer.Code.Controls
|
namespace Scrummer.Code.Controls
|
||||||
{
|
{
|
||||||
public class CTextBox: TextBox
|
public class CTextBox : TextBox, IValidableControl
|
||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
@@ -46,14 +46,9 @@ namespace Scrummer.Code.Controls
|
|||||||
|
|
||||||
public CTextBox()
|
public CTextBox()
|
||||||
{
|
{
|
||||||
Init += CTextbox_Init;
|
|
||||||
PreRender += CTextbox_PreRender;
|
PreRender += CTextbox_PreRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTextbox_Init(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTextbox_PreRender(object sender, EventArgs e)
|
void CTextbox_PreRender(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
CssClass = CssClassBase;
|
CssClass = CssClassBase;
|
||||||
@@ -79,11 +74,6 @@ namespace Scrummer.Code.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void RenderEndTag(HtmlTextWriter writer)
|
|
||||||
{
|
|
||||||
base.RenderEndTag(writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
@@ -93,6 +83,11 @@ namespace Scrummer.Code.Controls
|
|||||||
return string.IsNullOrEmpty(Text);
|
return string.IsNullOrEmpty(Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsValid()
|
||||||
|
{
|
||||||
|
return _allowEmpty || (string.IsNullOrEmpty(Text) == false);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
12
Scrummer/Code/Controls/IValidableControl.cs
Normal file
12
Scrummer/Code/Controls/IValidableControl.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Scrummer.Code.Controls
|
||||||
|
{
|
||||||
|
public interface IValidableControl
|
||||||
|
{
|
||||||
|
bool IsValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,5 +35,37 @@ namespace Scrummer.Code.Pages
|
|||||||
return pnlRow;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,6 +71,7 @@
|
|||||||
<Compile Include="Code\Controls\ChatHandler.cs" />
|
<Compile Include="Code\Controls\ChatHandler.cs" />
|
||||||
<Compile Include="Code\Controls\CLabel.cs" />
|
<Compile Include="Code\Controls\CLabel.cs" />
|
||||||
<Compile Include="Code\Controls\CTextBox.cs" />
|
<Compile Include="Code\Controls\CTextBox.cs" />
|
||||||
|
<Compile Include="Code\Controls\IValidableControl.cs" />
|
||||||
<Compile Include="Code\Entities\Message.cs" />
|
<Compile Include="Code\Entities\Message.cs" />
|
||||||
<Compile Include="Code\GlobalErrorHandler.cs" />
|
<Compile Include="Code\GlobalErrorHandler.cs" />
|
||||||
<Compile Include="Code\JSON\ParserContext.cs" />
|
<Compile Include="Code\JSON\ParserContext.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user