Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Security.Permissions;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace MyNamespace
- {
- [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
- [ToolboxData("<{0}:MyCustomValidator runat=\"server\"></{0}:MyCustomValidator>")]
- public class MyCustomValidator : CustomValidator
- {
- public MyCustomValidator()
- {
- this.SetFocusOnError = true;
- this.ValidateEmptyText = true;
- }
- protected override bool EvaluateIsValid()
- {
- string _target = this.ControlToValidate;
- WebControl obj = this.Parent.FindControl(_target) as WebControl;
- if (obj != null)
- {
- string value = this.GetControlValidationValue(_target);
- if (obj.Enabled && (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)))
- {
- obj.BorderColor = Color.LightPink;
- return false;
- }
- else if (obj.Enabled)
- obj.BorderColor = ColorTranslator.FromHtml("#a0a0a0");
- else
- obj.BorderColor = ColorTranslator.FromHtml("#e0e0e0");
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement