Click here to Skip to main content
15,922,427 members
Home / Discussions / C#
   

C#

 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 138463765-Aug-18 1:16
Member 138463765-Aug-18 1:16 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff5-Aug-18 1:28
mveOriginalGriff5-Aug-18 1:28 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Eddy Vluggen5-Aug-18 5:54
professionalEddy Vluggen5-Aug-18 5:54 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff5-Aug-18 6:07
mveOriginalGriff5-Aug-18 6:07 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Eddy Vluggen5-Aug-18 10:49
professionalEddy Vluggen5-Aug-18 10:49 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 138463766-Aug-18 9:18
Member 138463766-Aug-18 9:18 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff6-Aug-18 21:50
mveOriginalGriff6-Aug-18 21:50 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 138463767-Aug-18 3:23
Member 138463767-Aug-18 3:23 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Richard Deeming7-Aug-18 3:55
mveRichard Deeming7-Aug-18 3:55 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
OriginalGriff7-Aug-18 4:10
mveOriginalGriff7-Aug-18 4:10 
SuggestionRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Richard Deeming7-Aug-18 4:57
mveRichard Deeming7-Aug-18 4:57 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Member 1384637619-Aug-18 3:28
Member 1384637619-Aug-18 3:28 
GeneralRe: SelectedIndex doesn't work with the SelectionChanged event handler but it works with the ButtonClick event handler. Pin
Richard Deeming20-Aug-18 7:52
mveRichard Deeming20-Aug-18 7:52 
QuestionWant to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 7:57
indian1433-Aug-18 7:57 
AnswerRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Gerry Schmitz3-Aug-18 9:18
mveGerry Schmitz3-Aug-18 9:18 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 10:17
indian1433-Aug-18 10:17 
AnswerRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming3-Aug-18 10:21
mveRichard Deeming3-Aug-18 10:21 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 11:16
indian1433-Aug-18 11:16 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming3-Aug-18 12:14
mveRichard Deeming3-Aug-18 12:14 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1433-Aug-18 12:48
indian1433-Aug-18 12:48 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 2:05
mveRichard Deeming6-Aug-18 2:05 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 6:39
indian1436-Aug-18 6:39 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 7:15
mveRichard Deeming6-Aug-18 7:15 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 7:32
indian1436-Aug-18 7:32 
But still the attributes value in IEnumerable<attribute> attributes coming as null when I already have one Attribute on that class and when I try to expan the attributes collection object, it shows me "Enumeration yielded no results" in the end.
    public class LookupTable
    {
        public int Id { get; set; }

        [Required(ErrorMessage = "Code is required.")]<br />
        public string Code { get; set; }

        [Required(ErrorMessage = "Description is required.")]
        public string Description { get; set; }
        public int? ForeignKeyId { get; set; }
        public string ForeignKeyValue { get; set; }
        public DateTime? CreatedDate {get;set;} 
        public string CreatedBy {get;set;}       
        public int CodeLength { get; set; }
    }

Do I need to add anymore Attributes to the Code Property?, what am I missing here my friend?

Even after I changed my function to have Container instead of Model, still I get null at metadata.PropertyName

Always metadata.PropertyName is coming as null irrespective of any changes I do at if (metadata.PropertyName == GetPropertyName(() => model.Code) && (model.CodeLength > 0))
in the below function and attributes is also coming as null.
        protected override IEnumerable<System.Web.Mvc.ModelValidator> GetValidators(System.Web.Mvc.ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
        { 
            if (metadata.Model is LookupTable)
            {
                LookupTable model = metadata.Container as LookupTable;                

                if (metadata.PropertyName == GetPropertyName(() => model.Code) && (model.CodeLength > 0))
                {
                    var newAttributes = new List<Attribute>(attributes);
                    var stringLength = newAttributes.OfType<StringLengthAttribute>().FirstOrDefault();
                    if (stringLength != null)
                    {
                        newAttributes.Remove(stringLength);

                        if (model.CodeLength != 0)
                        {
                            newAttributes.Add(new StringLengthAttribute(model.CodeLength)
                            {
                                MinimumLength = model.CodeLength,
                                ErrorMessage = @"The field {{0}} length must be at least {model.CodeLength}."
                            });
                        }

                        attributes = newAttributes;
                    }
                }
            }            

            return base.GetValidators(metadata, context, attributes);
        }

Thanks,

Abdul Aleem

"There is already enough hatred in the world lets spread love, compassion and affection."
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 9:16
mveRichard Deeming6-Aug-18 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.