Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private string _SelectedValue;

        public DropDownValidation(string selectedValue)
        {
            _SelectedValue = selectedValue;
        }

        public override ValidationResult IsValid(object value, ValidationContext validationContext)
        {

            if (value != null)
            {
                if (_SelectedValue == "----Select Country----")
                {
                    return new ValidationResult("Select Some Country Please.");
                }
                else if (_SelectedValue == "----Select State----")
                {
                    return new ValidationResult("Select Some State Please.");
                }
                else if (_SelectedValue == "----Select City----")
                {
                    return new ValidationResult("Select Some City Please");
                }
            }
            return ValidationResult.Success;
        }

Error it is throwing is

Error	1	'ddl.Common.DropDownValidation.IsValid(object, System.ComponentModel.DataAnnotations.ValidationContext)': cannot change access modifiers when overriding 'protected' inherited member 'System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(object, System.ComponentModel.DataAnnotations.ValidationContext)'	
Posted
Updated 19-Jul-15 19:25pm
v2

1 solution

You could use scriptmanager on you submit.

VB
if ddl.selectedvalue = "-----Select Country-----" then
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.[GetType](), "showalert", "alert('Please Select A Country!');", True)
else

end if
 
Share this answer
 
Comments
lokopi.nagar 22-Jul-15 8:05am    
What is Me here

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900