Chevy Mark Sunderland

Chevy Mark Sunderland

  • NA
  • 188
  • 166.3k

Disable the RequiredFieldValidator where condition

Aug 5 2012 10:33 AM
Hello there.
First of all I must say that I am a newbie when it comes to net (C#).

Here is my problem.

I need enable or disable the RequiredFieldValidator in my aspx page where condition.
  1. If the TextBox ID="StartDateFag" and TextBox ID="StartEndFag" are empty or full I need disable the RequiredFieldValidator with ID="StartDateHoe1";
  2. If the TextBox ID="StartDateHoe" and TextBox ID="StartEndHoe" are empty or full I need disable the RequiredFieldValidator with ID="StartEndFag1";
I tried this code but in the all condition I have RequiredFieldValidator enables.

Can you help me?

If you have link for similar task, please give it me.
Can you explain any one or any sample code related this.

Your help would be very appreciated.
Thanks in advance for your time and hints.

Cheers.

<asp:TextBox ID="StartDateFag" runat="server" Width="70">
</asp:TextBox>
<asp:TextBox ID="StartEndFag" runat="server" Width="70">
</asp:TextBox>
<asp:RequiredFieldValidator ID="StartEndFag1" runat="server" Enabled="true" ControlToValidate="StartEndFag"
ErrorMessage=Error 1"></asp:RequiredFieldValidator>


<asp:TextBox ID="StartDateHoe" runat="server" Width="70">
</asp:TextBox>
<asp:TextBox ID="StartEndHoe" runat="server" Width="70">
</asp:TextBox>
<asp:RequiredFieldValidator ID="StartEndHoe1" runat="server" Enabled="true" ControlToValidate="StartEndHoe"
ErrorMessage=Error 2"></asp:RequiredFieldValidator>

if (s == "button1")
{
if (!string.IsNullOrEmpty(StartDateFag.Text) && !string.IsNullOrEmpty(StartEndFag.Text))
{
StartDateHoe1.Enabled = false;
}
else if (string.IsNullOrEmpty(StartDateFag.Text) == true && string.IsNullOrEmpty(StartDateFag.Text) == true)
{
StartDateHoe1.Enabled = false;
}
}



if (s == "button2")
{
if (!string.IsNullOrEmpty(StartDateHoe.Text) && !string.IsNullOrEmpty(StartEndHoe.Text))
{
StartEndFag1.Enabled = true;
}
else if (string.IsNullOrEmpty(StartDateHoe.Text) == true && string.IsNullOrEmpty(StartEndHoe.Text) == true)
{
StartEndFag1.Enabled = false;
}
}

Answers (2)