0

我是动态创建的文本框。所以它必须由用户字段。所以我想添加类似“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 />"));
                }

任何想法?

4

1 回答 1

0

试试这样的..

RequiredFieldValidator req = new RequiredFieldValidator();
req.ID = "Req" + NumberOfControls;;
req.ControlToValidate = "Fname" + NumberOfControls;;
req.ErrorMessage = "Name Required";
reqfldVal.SetFocusOnError = true;
AdultsListPlaceholder.Controls.Add(req);
于 2013-04-09T07:42:59.127 回答