Click here to Skip to main content
Rate this: bad
good
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 asp.net 3.5.I have worked with the same peice of code in asp.net 2.0 and there it is working fine.
 

 
Regards,
P.Sri Pavan
Posted 10-Nov-10 0:50am
Comments
jim lahey at 10-Nov-10 6:06am
   
if it works in 2.0 you should be ok in 3.5 also
Ankur\m/ at 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
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Enable or Disable ASP.Net Validation on client side
rfvOther: is a Required Field Validator
Collapse
 
//Syntax:
ValidatorEnable(ValidatorContronName,Boolean);
//Explanation:ValidatorContronName - This is ClientID of the Validation control.
Boolean - true(Enable) / false(Disable)
//Example:
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]
 
Thanks,
Imdadhusen
  Permalink  
Rate this: bad
good
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:DropDownList>
        <asp:TextBox ID="txt" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="Validator1" runat="server" ControlToValidate="txt"
            ErrorMessage="error"></asp:RequiredFieldValidator>
        <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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
v2

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 28 Nov 2013
Copyright © CodeProject, 1999-2014
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