ASP.NET CustomValidator on dynamic textboxes

T

theresa

Hello. I'm creating a form that has (up to) 10 identical panels on the
page, with each panel containing the same 8 textboxes for things like
school name, address, etc, and one dropdown box. The user chooses how
many schools they need to enter information for, and the form shows the
appropriate number of panels. All 10 panels are generated on page load,
then hidden until the user selects how many they need.

Now comes the tricky part. If the user selects "No" from the dropdown
box within a panel, the address for that panel needs to be required.
I've written a CustomValidator that refers to the Address textbox by ID
(eg. Address1). While the CustomValidator works, if I use this method I
will have to write separate CustomValidators for each of the 10 panels.
Is there any way to write one validator that would work for all 10
Address textboxes? Here's the code I've got so far:

Sub reqAddress(sender as Object, args as ServerValidateEventArgs)

Dim strAddress As String
Dim ddYesNo As String = CStr(args.Value)

strAddress = txtAddress1.Text // This is the line I want to make more
general

If ddYesNo = "No" And Len(strAddress)=0 Then
args.IsValid = False
Else
args.IsValid = True
End If

End Sub
 
G

Guest

control array?

for x = 1 to 10
strAddress = txtAddresses[x].Text

pseudocode obviously :)
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top