how to assign target control to validator control on serverside
I am having N numbers of Text boxes those are generating dynamically. I want to validate each textbox for Formate HH:MM:SS PM/AM so i dynamicaly create开发者_StackOverflow the validation control . but as the dynamic textbox has no ID , so what i have to pass to the Validation control for ControlToValidate Property ?
AccordionPane ap1; for (int i = 0; i <= 2; i++) { ap1 = new AccordionPane(); ap1.HeaderContainer.Controls.Add(new LiteralControl("Using Markup")); Panel pnl = new Panel();
TextBox txtTime = new TextBox();
txtTime.ID = "txtTimeBox" + i;
txtTime.ValidationGroup = "MKE";
RegularExpressionValidator validateDate = new RegularExpressionValidator();
validateDate.ValidationExpression = "(0[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]|60) (AM|PM|am|pm)";
validateDate.ControlToValidate = txtTime.ID;
validateDate.ErrorMessage = "Invalid Date. Try in HH:MM:SS AM/am|PM/pm format";
pnl.Controls.Add(txtTime);
ap1.ContentContainer.Controls.Add(pnl);
MyAccordion.Panes.Add(ap1);
}
Page.Controls.Add(divContainer);
精彩评论