views:

448

answers:

1

I am using ASP .NET (C#) and have a page with a listview linked to a sqldatasource.

The listview has a InsertItemTemplate which contains many textboxes. I want to make all the textboxes required via the RequiredFieldValidator (and the ValidatorCallOutExtender).

Is there a way to do this in the codebehind instead of the aspx page?

Ideally I would like the page to validate each control with the same method with only the error message changing.

A: 

I take it your question is about dynamically adding controls (and not about codebehind validation).

I didn't know and ran a few tests. It is possible to simply add (Validator)controls to the Controls property of the Form element, but controlling the order is not so simple (no Controls.Insert()).

So my advice would be not to use a plain TextBox but a UserControl. You could probably use Search&Replace to fix up the ItemTemplate.

Henk Holterman
Sorry - my question was about codebehind validation.
John M
With (only) codebehind you loose the advantages of client-side validation. I stick with the UserControls.
Henk Holterman