Files
mono/mcs/class/System.Web/System.Web.UI.WebControls/CustomValidator.cs
T
Gaurav Vaish cea71236b2 2002-03-16 Gaurav Vaish <[email protected]>
* Trying to go for a build... changes due to the same...

svn path=/trunk/mcs/; revision=3139
2002-03-16 00:59:22 +00:00

109 lines
2.3 KiB
C#

/**
* Namespace: System.Web.UI.WebControls
* Class: CustomValidator
*
* Author: Gaurav Vaish
* Maintainer: [email protected]
* Contact: <[email protected]>, <[email protected]>
* Implementation: yes
* Status: 100%
*
* (C) Gaurav Vaish (2002)
*/
using System;
using System.Web;
using System.Web.UI;
namespace System.Web.UI.WebControls
{
public class CustomValidator : BaseValidator
{
private static readonly object ServerValidateEvent = new object();
public CustomValidator()
{
}
public string ClientValidationFunction
{
get
{
object o = ViewState["ClientValidationFunction"];
if(o != null)
{
return (string)o;
}
return String.Empty;
}
set
{
ViewState["ClientValidationFunction"] = value;
}
}
public event ServerValidateEventHandler ServerValidate
{
add
{
Events.AddHandler(ServerValidateEvent, value);
}
remove
{
Events.RemoveHandler(ServerValidateEvent, value);
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
if(RenderUplevel)
{
writer.AddAttribute("evaluationfunction", "CustomValidatorEvaluateIsValid");
if(ClientValidationFunction.Length > 0)
{
writer.AddAttribute("clientvalidationfunction", ClientValidationFunction);
}
}
}
protected override bool ControlPropertiesValid()
{
if(ControlToValidate.Length > 0)
{
CheckControlValidationProperty(ControlToValidate, "ControlToValidate");
}
return true;
}
protected virtual bool OnServerValidate(string value)
{
if(Events != null)
{
ServerValidateEventHandler sveh = (ServerValidateEventHandler)(Events[ServerValidateEvent]);
if(sveh != null)
{
ServerValidateEventArgs args = new ServerValidateEventArgs(value, true);
sveh(this, args);
return args.IsValid;
}
}
return true;
}
protected override bool EvaluateIsValid()
{
string ctrl = ControlToValidate;
if(ctrl.Length > 0)
{
ctrl = GetControlValidationValue(ctrl);
if(ctrl== null || ctrl.Length == 0)
{
return true;
}
}
return OnServerValidate(ctrl);
}
}
}