Listing 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace AjaxValidation
{
    [DisplayName("AJAX Field Validation")]
    public class AjaxValidationRule: ValidationRule
    {
        private string _control = "";

        [Description("Control To Validate"), DisplayName("Control Name")]
        public string ControlName
        {
            get { return _control; }
            set { _control = value; }
        }
        private string _value = "";

        [Description("Value of the control to validate."), DisplayName("Value")]
        public string Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public override void Validate(object sender, ValidationEventArgs e)
        {
            Regex r = new Regex("id=\"" + _control + "\".*>" + _value + "<");
            MatchCollection m = r.Matches(e.Response.BodyString);
            e.IsValid = (m.Count > 0);
        }
    }
}
comments powered by Disqus
Most   Popular
Upcoming Events

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.