Validation on controls within a repeater

O

Octavie

Hai there!

I've build a web user control which contains a repeater control. This
repeater control has several textboxes which need to be validated. The
repeater is bound to a dataset that contains a datatable with empty rows.

The validation I need is to check whether a value has been provided (like
Required). So, if the datatable has 3 rows, then the repeater shows also 3
item rows each containing the textboxes.

How to do the validation on the textboxes?

Thanxxxxx...
Octavie
 
T

Teemu Keiski

Hi,

just place a RequiredFieldValidator inside the same ItemTemplate where
TextBox to be validated is located (and give it the ID of the TextBox to
ControlToValidate attribute).

<%-- repeater item starts here --%>
<ItemTemplate>
<asp:TextBox ID="txtInrepeater" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="txtInrepeater"
runat="server" ErrorMessage="Input
required!">*</asp:RequiredFieldValidator>
</ItemTemplate>
<%-- repeater item ends here --%>

This way every TextBox created by binding the repeater aso ahs associated
RequiredFieldValidator which means that input must be provided for each of
them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top