Programmatically adding validation control to asp.net page?

Try adding the control to the Form of the page. The reason for this is that you need to add this type of controls to a form.

Up vote 2 down vote favorite share g+ share fb share tw.

I am trying to add a required fields validator programmatically in asp.net. But I get the following error message - Control 'req2' of type 'RequiredFieldValidator' must be placed inside a form tag with runat=server The c# code I have used is below - 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); } Could someone tell me whats gone wrong here?

Thanks for sharing your valuable time. Asp.net validation form-validation link|improve this question edited Dec 18 '09 at 7:09Jay Riggs19.5k42040 asked Dec 18 '09 at 7:07IrfanRaza481827 96% accept rate.

Try adding the control to the Form of the page. The reason for this is that you need to add this type of controls to a form. This.Form.Controls.

Add(rv).

Yeah that worked. Thanks Smazy! – IrfanRaza Dec 18 '09 at 7:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions