Dynamically created Validation controls
-
I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.
-
I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.
What is the error you receive??
Nidhi.s wrote:
txtBoxReEnterPassword.Controls.Add(rfldValidator);
You're not supposed to add the validator as control of the textbox, you should add the control to, for example, your form... this.Controls.Add(); further, the use if strings is a but... erhm... fault sensitive.. use ControlInstance.Name in stead of "txtReEnterPassword";
.: I love it when a plan comes together :. http://www.zonderpunt.nl
-
I have dynamically created the textboxes .Now I want to add a Requiredfield validator with a txtbox. I am trying like this: TextBox txtBoxReEnterPassword = new TextBox(); ---Some other Code---- RequiredFieldValidator rfldValidator = new RequiredFieldValidator(); rfldValidator.Text = "Enter same Password"; rfldValidator.ID = "compvaldtor"; rfldValidator.ErrorMessage = "Enter Password"; rfldValidator.ControlToValidate = "txtReEnterPassword"; txtBoxReEnterPassword.Controls.Add(rfldValidator); But it's not working.