Click here to Skip to main content
11,921,138 members (62,137 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
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 10-Nov-10 0:50am
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"Thumbs Up | :thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.Rose | [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
0 OriginalGriff 583
1 Dave Kreskowiak 245
2 phil.o 160
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,951
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,171
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 28 Nov 2013
Copyright © CodeProject, 1999-2015
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