📄 customvalidator.cs
字号:
using System;
namespace System.Web.UI.WebControls
{
/// <summary>
/// Summary description for CustomValidator.
/// </summary>
public class CustomValidator:BaseValidator
{
static object EventServerValidate;
static CustomValidator()
{
CustomValidator.EventServerValidate = new Object();
}
public CustomValidator() : base()
{
}
protected virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
this.AddAttributesToRender(writer);
if (this.RenderUplevel)
{
writer.AddAttribute("evaluationfunction", "CustomValidatorEvaluateIsValid");
if (this.ClientValidationFunction.Length > 0)
writer.AddAttribute("clientvalidationfunction", this.ClientValidationFunction);
}
}
protected virtual bool ControlPropertiesValid()
{
string local0;
local0 = this.ControlToValidate;
if (local0.Length > 0)
this.CheckControlValidationProperty(local0, "ControlToValidate");
return true;
}
protected override bool EvaluateIsValid()
{
string local0;
string local1;
local0 = "";
local1 = this.ControlToValidate;
if (local1.Length > 0)
{
local0 = this.GetControlValidationValue(local1);
if (local0 == null || local0.Trim().Length == 0)
return true;
}
return this.OnServerValidate(local0);
}
protected virtual bool OnServerValidate(string value)
{
ServerValidateEventHandler local0;
ServerValidateEventArgs local1;
local0 = (ServerValidateEventHandler) this.Events[CustomValidator.EventServerValidate];
local1 = new ServerValidateEventArgs(value, true);
if (local0 != null)
{
local0(this, local1);
return local1.IsValid;
}
return true;
}
public event System.Web.UI.WebControls.ServerValidateEventHandler ServerValidate
{
add
{
this.Events.AddHandler(CustomValidator.EventServerValidate, value);
}
remove
{
this.Events.RemoveHandler(CustomValidator.EventServerValidate, value);
}
}
public string ClientValidationFunction
{
get
{
object local0;
local0 = this.ViewState["ClientValidationFunction"];
if (local0 != null)
return (String) local0;
return System.String.Empty;
}
set
{
this.ViewState["ClientValidationFunction"]= value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -