| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /**
- * 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");
- }
- }
-
- 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;
- }
- }
- }
|