This is a migrated thread and some comments may be shown as answers.

DataForm ValidationSummary

6 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sumati
Top achievements
Rank 1
Sumati asked on 22 Jun 2010, 10:31 AM
1) In my web application, I have 6 dropdown and 4 textboxes. If user clicks for commit without entering any data then validationsummary will show 10 error message which is fine. Issue is that order of that message will not be same as the order of the controls shown on the web page. How to make sure that order will be same? I debugged the code and notice that ValidationSummary.Errors and ValidationSummary.DisplayErrors array object is different in order. I am using Silverlight 3.

2) Also, how can I make the respective control to be highlighted with red border when user clicks on any of the error?

6 Answers, 1 is accepted

Sort by
0
Sumati
Top achievements
Rank 1
answered on 22 Jun 2010, 11:46 AM
I answered the first point on my own:

Answer 1)  I making use of custom validation and missed to specify second arguement to 'ValidationResult'
Second arguement should be the name of the property to be validated

Answer 2) Manual changed border color on SelectionChanged event of ValidationSummary
0
Vinh
Top achievements
Rank 1
answered on 14 Sep 2010, 10:57 PM
Can you share an example of your code? I ran into the same issue and I'm new to this so I don't really understand your answer. Thx.
0
Sumati
Top achievements
Rank 1
answered on 15 Sep 2010, 02:23 AM
Part 1)

Firstly, specify the following attribute in Contract object:

[Required]

[CustomValidation(typeof(HelperClass.Validation), "IsValueSelected")]

[DataMember]

public string DropDownSelectItemID { get; set; }

Then in "HelperClass.Validation", do the following

 

namespace HelperClass

{

public static class Validation

{

public static ValidationResult IsValueSelected(this string selectedValue, ValidationContext validationContext)

{

if (selectedValue == "-1")

{

string[] memeberNames = new string[] { validationContext.MemberName };

switch (validationContext.MemberName)

{

case "DropDownSelectItemID":

return new ValidationResult("Please select a value from the drop down", memeberNames);

break;

}

}

else

{

return ValidationResult.Success;

}

}

}

}



Part 2) You need to just hook the selectionchanged event and change the border color
0
Vinh
Top achievements
Rank 1
answered on 17 Sep 2010, 09:12 PM
Sumati,

Thanks for your response. I was able to bind the combobox to to the datafield of dataform but the validation summary sees it as an object validation error and not as a property validation error which is why I have to find a way to set the combobox with red border color. The problem still remains that the order of the validation errors in the validation summary of the dataform doesn't show up in correct order as the elements on the Form when I have combination of comboboxes, checkboxes and textboxes. It seems to work correctly with textboxes only. The following questions still remains:
1) How do you set the tool tips with red background just like the tool tips appearing at the top right corner when validation fails for a textbox field?
2) How do you get the order of the errors to display correctly using validation summary when you have both property validation errors and object validation errors (from meta class for the object using RIA services,...)?
0
Sumati
Top achievements
Rank 1
answered on 20 Sep 2010, 02:19 AM

Vinh

1) I am not showing any tooltip on top-right corner of a combobox.
I am just setting the border color to red on selectionChanged event of ValidationSummary.
Maybe you need to google more on this task.

2) My issue of displaying order of errors was fixed by specifying
the second parameter to the function "ValidationResult()" as showh below

case "DropDownSelectItemID":

return new ValidationResult("Please select a value from the drop down", memeberNames);

break;

Maybe you can just remove second argument -> See the result -> Then apply second parameter -> See the result.

Might be you are implementing some other event which is causing above lines of code to not take effect.
My advice would be to concentrate on one task. Comment other lines of code related to ValidationSummary and proceed to step by step to correct order of display errors.

0
Vinh
Top achievements
Rank 1
answered on 20 Sep 2010, 04:19 PM
Sumati,

Thanks for your advice. I'll try to follow them and see how it turns out.
Tags
General Discussions
Asked by
Sumati
Top achievements
Rank 1
Answers by
Sumati
Top achievements
Rank 1
Vinh
Top achievements
Rank 1
Share this question
or