Reputation: 902
iam dynamically generating two textboxes
on add textbox
button
which is working fine but i want to validate the value of that textboxes
as well but when i apply validation and run the page and click add button nothing happens when i debug the code there is no error and the control executes all the lines but if i comment the validation code then add button works fine
see here
TextBox addtimeout = new TextBox();
addtimeout.ID = "addtimeout" + j;
addtimeout.EnableViewState = true;
PlaceHolder2.Controls.Add(addtimeout);
RegularExpressionValidator rev = new RegularExpressionValidator();
rev.ValidationExpression = "^(1[0-2]|0[1-9]):[0-5][0-9]\040(AM|am|PM|pm)$";
rev.ControlToValidate = addtimeout.Text;
rev.ErrorMessage = "Invalid time format. Time format HH:MM AM/PM";
rev.Enabled = true;
PlaceHolder2.Controls.Add(rev);
PlaceHolder2.Controls.Add(new LiteralControl("<br />"));
tell me what i am doing wrong??
UPDATE
rev.ControlToValidate = addtimeout.ID;
still not working.
Upvotes: 0
Views: 1217
Reputation: 4328
Generally...IF you make dynamic code for validation than try to add validationGroup property...to make consistant validation...
Upvotes: 0
Reputation: 8119
Control to Validate Requires the Id of your control i.e. but you are passing the text of your text box so to make it work.
Change
rev.ControlToValidate = addtimeout.Text;
to
rev.ControlToValidate =addtimeout.ID;
Control to Validate Requires the Id of your control i.e. but you are passing the text of your text box
Upvotes: 1