Avatar of gagnonmv
gagnonmvFlag for United States of America asked on

Turn RequiredFieldValidators Enable/Disable If TextBox Empty

I have a web form that works well but I need to turn on/off requiredfiledvalidator depending on if certain textboxes have been completed or are empty.

I need an example of JavaScript using the following example:  Also where is this code placed? On the aspx page, aspx.vb page or on the function.vb page.

If TextBox1 empty then require TextBox2, TextBox3 requiredfieldvalidator enabled else........

Thanks
ASP.NETJavaScriptProgramming

Avatar of undefined
Last Comment
gagnonmv

8/22/2022 - Mon
raterus

I would use a CustomValidator for this, the built-in RequiredFieldValidators don't have any way to conditionally check based on circumstances.

You can place the javascript anywhere in the page, and use the ClientValidationFunction property to specify the function name.
ASKER
gagnonmv

Here's what I have so can you give me an example:
So If Job_Number Empty then Enable Required Field Fund:

Thanks

                        <td valign="top" style="width: 173px">
            <asp:RegularExpressionValidator ID="RegularExpressionValidator12" runat="server" validationexpression="^[A-Z0-9\s]{8,8}$" ErrorMessage="Enter Letters in UPPER Case and the entry must be 8 Characters in Length." ControlToValidate="JOB_NUMBER" Display="Dynamic" CssClass="error"></asp:RegularExpressionValidator>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator15" Enabled="false" runat="server" ErrorMessage="Required Entry" ControlToValidate="JOB_NUMBER" Display="Dynamic" CssClass="error" Font-Size="Small" />            
            <asp:TextBox ID="Job_Number" MaxLength="8" runat="server" ToolTip="Enter the Eight (8) Character Job Code.  Example IDP40108."></asp:TextBox></td>
 
 
                        <td valign="top" style="width: 173px">
            <asp:RegularExpressionValidator ID="RegularExpressionValidator14" runat="server" validationexpression="^[A-Z0-9\s]{4,4}$" ErrorMessage="Enter Letters in UPPER Case and the entry must be 4 Characters in Length." ControlToValidate="FUND" Display="Dynamic" CssClass="error"></asp:RegularExpressionValidator>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator17" Enabled="false" runat="server" ErrorMessage="Required Entry" ControlToValidate="FUND" Display="Dynamic" CssClass="error" Font-Size="Small" />            
            <asp:TextBox ID="Fund" MaxLength="4" runat="server" ToolTip="Enter the Four (4) Character Fund.  Example: CNCN"></asp:TextBox></td>

Open in new window

ASKER CERTIFIED SOLUTION
raterus

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
raterus

You cannot delete a question when you don't respond to expert comments.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
gagnonmv

Okay, but you provided me with no examples and no answer.  Basically you told me to find the answer myself.