我是动态创建的文本框。所以它必须由用户填写。 所以我想添加像“RequiredFieldValidator”这样的东西。但我不知道如何动态添加。如果不填写动态文本框,用户无法进入下一步。那么我该如何控制呢?
这是我的代码
for (int i = count; i < no; i++)
{
Label lb = new Label();
lb.ID = "lbFname" + NumberOfControls;
lb.Text = "First Name :";
TextBox tbx = new TextBox();
tbx.ID = "Fname" + NumberOfControls;
AdultsListPlaceholder.Controls.Add(lb);
AdultsListPlaceholder.Controls.Add(tbx);
NumberOfControls++;
AdultsListPlaceholder.Controls.Add(new LiteralControl("<br />"));
AdultsListPlaceholder.Controls.Add(new LiteralControl("<br />"));
}
任何想法?
答案 0 :(得分:0)
尝试这样的事情......
RequiredFieldValidator req = new RequiredFieldValidator();
req.ID = "Req" + NumberOfControls;;
req.ControlToValidate = "Fname" + NumberOfControls;;
req.ErrorMessage = "Name Required";
reqfldVal.SetFocusOnError = true;
AdultsListPlaceholder.Controls.Add(req);