Click here to Skip to main content
13,043,491 members (52,340 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Friends,

Can any one help me how to enable or disable the required field validator control based on selection of Dropdown list in 3.5.I have worked with the same peice of code in 2.0 and there it is working fine.

P.Sri Pavan
Posted 9-Nov-10 23:50pm
jim lahey 10-Nov-10 6:06am
if it works in 2.0 you should be ok in 3.5 also
Ankur\m/ 10-Nov-10 6:32am
As Jim said, it should work fine with 3.5 also.
Are you getting any error? Can you put up your relevant code here?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Enable or Disable ASP.Net Validation on client side
rfvOther: is a Required Field Validator

//Explanation:ValidatorContronName - This is ClientID of the Validation control.
Boolean - true(Enable) / false(Disable)
ValidatorEnable(document.getElementById('<%=rfvOther.ClientID%>'), false);

You can implement this function according you logic.

Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can easily disable the validator on the server side

Follow the example:

<asp:DropDownList ID="DDL1" runat="server" AutoPostBack="true">
            <asp:ListItem Value="1">One</asp:ListItem>
            <asp:ListItem Value="2">Two</asp:ListItem>
            <asp:ListItem Value="3">Three</asp:ListItem>
        <asp:TextBox ID="txt" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="Validator1" runat="server" ControlToValidate="txt"
        <asp:Button runat="server" Text="Save" />

and this piece place into your server side page class:

public partial class WebForm1 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        Validator1.Enabled = Request[DDL1.UniqueID] == "2" ? false : true;

When you select "Two" in your dropdown, it will disable the validator
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 28 Nov 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100