Conditionally required property using data annotations

RequiredIf validation attribute I’ve written a RequiredIfAttribute that requires a particular property value when a different property has a certain value (what you require) or when a different property has anything but a specific value. This is the code that may help: /// <summary> /// Provides conditional validation based on related property value. /// </summary> … Read more

Change Text Box Color using Required Field Validator. No Extender Controls Please

What you can do is register a Javascript function that will iterate through the global Page_Validators array after submission and you can set the background appropriately. The nice thing about this is that you can use it on all of your controls on the page. The function looks like this: function fnOnUpdateValidators() { for (var … Read more

How to add a RequiredFieldValidator to DropDownList control?

For the most part you treat it as if you are validating any other kind of control but use the InitialValue property of the required field validator. <asp:RequiredFieldValidator ID=”rfv1″ runat=”server” ControlToValidate=”your-dropdownlist” InitialValue=”Please select” ErrorMessage=”Please select something” /> Basically what it’s saying is that validation will succeed if any other value than the 1 set in … Read more