aspxページに「add another」という名前のボタンがあります。ユーザーがボタンをクリックすると、新しいテキストボックスがRequiredFieldValidatorとともに追加されます。検証でコントロールを動的に追加する方法
私はこのようなコードを使用しよう:
protected void btn_Click(object sender, EventArgs e)
{
TextBox control = new TextBox();
control.Text = "";
control.ID = "txt2";
divMy.Controls.Add(control);//divMy is the container of all the textbox
RequiredFieldValidator rfv2 = new RequiredFieldValidator();
rfv2.ID = "rfv2";
rfv.ControlToValidate = control.ID;
rfv.ErrorMessage = "bbb";
divV.Controls.Add(rfv2);//divV is the container of all validations.
}
それは動作しません。どのような正しい方法は、この機能を達成するために?
助けていただきありがとうございます。