S
sebastien.varoteaux
Hi all,
I have a form on which i add n * 2 TextBox dynamically.
I would like to validate them with a CustomValidator.
I do it like that (calling from OnInit method):
parentControl.Controls.Add(new LiteralControl("<label for=\"" +
"tbFirstname" + counter + "\">Firstname</label>"));
TextBox aChildBox = new TextBox();
aChildBox.ID = "tbFirstname" + counter;
parentControl.Controls.Add(aChildBox);
CustomValidator aCustomValidator = new CustomValidator();
aCustomValidator.EnableClientScript = false;
aCustomValidator.ControlToValidate = aChildBox.ID;
aCustomValidator.Display = ValidatorDisplay.Dynamic;
aCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandler(this.name_validator);
aCustomValidator.Enabled = true;
this.Validators.Add(aCustomValidator);
When i click my submit button, validation go on. But...
I have the following error:
NullReferenceException: La référence d'objet n'est pas définie à
une instance d'un objet.]
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String
name, String propertyName)
System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid()
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid()
System.Web.UI.WebControls.BaseValidator.Validate()
System.Web.UI.Page.Validate()
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
I do not want to valid these fields manually because i am sure that
it's possible!
Is somebody could help me?
Best regards
I have a form on which i add n * 2 TextBox dynamically.
I would like to validate them with a CustomValidator.
I do it like that (calling from OnInit method):
parentControl.Controls.Add(new LiteralControl("<label for=\"" +
"tbFirstname" + counter + "\">Firstname</label>"));
TextBox aChildBox = new TextBox();
aChildBox.ID = "tbFirstname" + counter;
parentControl.Controls.Add(aChildBox);
CustomValidator aCustomValidator = new CustomValidator();
aCustomValidator.EnableClientScript = false;
aCustomValidator.ControlToValidate = aChildBox.ID;
aCustomValidator.Display = ValidatorDisplay.Dynamic;
aCustomValidator.ServerValidate += new
System.Web.UI.WebControls.ServerValidateEventHandler(this.name_validator);
aCustomValidator.Enabled = true;
this.Validators.Add(aCustomValidator);
When i click my submit button, validation go on. But...
I have the following error:
NullReferenceException: La référence d'objet n'est pas définie à
une instance d'un objet.]
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String
name, String propertyName)
System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid()
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid()
System.Web.UI.WebControls.BaseValidator.Validate()
System.Web.UI.Page.Validate()
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
I do not want to valid these fields manually because i am sure that
it's possible!
Is somebody could help me?
Best regards