1

I have two html input in one form, and I am setting them to required as follows:

<input id="email" name="textfield36" type="text" class="input3" runat="server" required="required" />
<input id="frEmail" name="textfield36" type="text" class="input3" runat="server" required="required" />

I need to set the Required attribute to false to one of the two inputs from c#. For example:

if (language == "English")
{
    frEmail.Attributes.Add("required", "false");
}
else
{
    email.Attributes.Add("required", "false");
}

This is causing an issue, because if the language is English, then the user only needs to fill the specified fields and the way it's happening now is that he's obliged to fill them all and vice versa. Note that on load I'm hiding the fields not relating to the language.

Can anyone help on this?

Hanady
  • 779
  • 2
  • 15
  • 38
  • Both your conditions are set to false?? – AndrewL64 Mar 12 '15 at 21:46
  • No, when the language is English, email input should only be required, and frEmail should't. And if the language is other than English, then frEmail should only be required and email input shouldn't. – Hanady Mar 12 '15 at 21:48

1 Answers1

2

The required attribute is a Boolean attribute. That means the value is ignored. It's presence on the element all that matters. You need to remove the required attribute, not change its value.

email.Attributes.Remove("required");
Community
  • 1
  • 1
gilly3
  • 87,962
  • 25
  • 144
  • 176