I am trying to add a required field program code to an asp.net file. But I get the following error message: Control 'req2' of type 'RequiredFieldValidator' should be placed inside the form tag using runat = server
The C # code I used below is
protected void Page_Load(object sender, EventArgs e)
{
RequiredFieldValidator rv = new RequiredFieldValidator();
rv.ID = "req2";
rv.ControlToValidate = "TextBox2";
rv.ErrorMessage = "Data Required";
this.Controls.Add(rv);
}
Can someone tell me what's wrong here?
Thank you for sharing your valuable time.
source
share