Link to home
Start Free TrialLog in
Avatar of cdlciddit

asked on

Can I use one RequiredFieldValidator for multiple controls?

Hello I have a series of text boxes to record telephone numbers.  Like this:
Phone Number: (<asp:TextBox ID="txtContHomePh1" runat="server" MaxLength="3" Width="32px"></asp:TextBox>
                       <asp:TextBox ID="txtContHomePh2" runat="server" MaxLength="3" Width="31px"></asp:TextBox>
                       <asp:TextBox ID="txtContHomePh3" runat="server" MaxLength="4" Width="49px"></asp:TextBox>

Open in new window

txtContHomePh1 is the area code, txtContHomePh2 is for the next 3 number, and txtContHomePh3 is for the last 4 digits. I want a RequiredFieldValidator to make sure the user fills out the boxes.  Can I use just 1 for all 3 textboxes? Or do I have to put one on each text box?
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdlciddit


thank you @zephyr_hex (Megan).   I was hoping there was another way.  I appreciate you responding so quickly.
If you wanted to use jQuery / JavaScript instead, you could use a class on your required elements and bind them to one function that handles the validation.
But ASP .NET validation controls can only be linked to one control.