Esempio n. 1
0
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            if (string.IsNullOrEmpty(this.ControlToValidate))
            {
                throw new ArgumentNullException("ControlToValidate");
            }
            WebControl control = (WebControl)this.NamingContainer.FindControl(this.ControlToValidate);

            if ((control != null) && (this.Validators.Count > 0))
            {
                this.targetClientId = control.ClientID;
                if (!(control is RadioButtonList))
                {
                    control.Attributes.Add("ValidateGroup", this.ValidateGroup);
                }
                if (!string.IsNullOrEmpty(this.ContainerId))
                {
                    ValidatorContainer container = (ValidatorContainer)this.Page.FindControl(this.ContainerId);
                    if (container == null)
                    {
                        container = this.FindFromMasterPage();
                    }
                    if (container == null)
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "The validator container: '{0}' was not found", new object[] { this.ContainerId }));
                    }
                    this.CreateToContainer(container);
                }
                else
                {
                    this.CreateToChilds();
                }
            }
        }
Esempio n. 2
0
        private ValidatorContainer FindFromMasterPage()
        {
            Control            namingContainer = this.NamingContainer;
            ValidatorContainer container       = (ValidatorContainer)namingContainer.FindControl(this.ContainerId);

            while ((container == null) && (namingContainer.Parent != null))
            {
                namingContainer = namingContainer.Parent;
                container       = (ValidatorContainer)namingContainer.FindControl(this.ContainerId);
            }
            return(container);
        }
Esempio n. 3
0
 private void CreateToContainer(ValidatorContainer container)
 {
     if (container != null)
     {
         this.Validators[0].SetOwner(this);
         container.AddValidatorControl(this.Validators[0].GenerateInitScript());
         for (int i = 1; i < this.Validators.Count; i++)
         {
             this.Validators[i].SetOwner(this);
             container.AddValidatorControl(this.Validators[i].GenerateAppendScript());
         }
     }
 }