Click here to Skip to main content
16,021,710 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I am preparing a control by extending TextBox. Here i included RequiredFieldValidator and range validators. But these are not working. Can you help me?Below is the code for CustomControl.
public class PasswordTextBox : TextBox
    {
        RequiredFieldValidator rfv = new RequiredFieldValidator();
        RangeValidator rv = new RangeValidator();

        private string minlength;
       public string Minlength
       {
           get { return minlength; }
           set { minlength = value; }
       }
       private string maxlength;
       public string Maxlength
       {
           get { return maxlength; }
           set { maxlength = value; }
       }

       protected override void OnInit(EventArgs e)
       {
           this.TextMode = TextBoxMode.Password;
           rfv.ErrorMessage = "*";
           rfv.ControlToValidate = this.ClientID;
           rv.ErrorMessage = "Password is not in range";
           rv.ControlToValidate = this.ClientID;
           rv.MinimumValue = minlength.ToString();
           rv.MaximumValue = maxlength.ToString();
       }
       protected override void RenderContents(HtmlTextWriter output)
       {
           this.RenderControl(output);
           rfv.RenderControl(output);
           rv.RenderControl(output);
       }
}
Posted
Updated 15-May-11 19:22pm
v2

1 solution

You may want your control to inherit the IValidator interface as well. The IValidator contains the following properties :
C#
public string ErrorMessage
public bool IsValid

and the method
C#
public void Validate()

So your class declaration would be :
C#
public class PasswordTextBox : TextBox, IValidator

Good luck!
Eduard
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900