So we are trying to put the wraps on out ASP.Net 2.0 app for a client here and I thought it would be cool to check out the ValidationGroup thing that they added to the Validators. So lets say I have something like this for example:
<asp:DropDownList ID="survey_list" runat="server" />
<asp:RequiredFieldValidator InitialValue="" Id="RequiredFieldValidator3"
runat="Server" Display="dynamic"
ControlToValidate="survey_list" ErrorMessage="You must select a survey to copy to." /> <asp:DropDownList ID="survey_questionsstart" runat="server" OnDataBound="list_DataBound" />
<asp:RequiredFieldValidator InitialValue="" Id="RequiredFieldValidator1" runat="Server" ControlToValidate="survey_questionsstart" ValidationGroup="CopyByRange" ErrorMessage="You must select a start question." />
<asp:Button ID="btnAddByRange" runat="server" Text=" Copy " OnClick="btnAddByRange_Click" CausesValidation="true" ValidationGroup="CopyByRange" /> <asp:DropDownList ID="questionlist" runat="server" OnDataBound="list_DataBound" />
<br />
<asp:RequiredFieldValidator InitialValue="" Id="RequiredFieldValidator4" runat="Server" Display="dynamic" ControlToValidate="questionlist" ValidationGroup="CopySingleQuestion" ErrorMessage="You must select a question." /> So it's a dropdownlist of Surveys, followed by a question list and a button to copy a range of questions followed by another dropdown of questions and a button to copy a single question.
What I decided todo was have a ValidationGroup on each button so the validators could be seperated and give the user a rich UI so they can correct any mistakes they have.
Now what I would think would happen would be that if I click on either of the buttons the ValidationGroup would fire and then any items that don’t have a group would fire. Unfortunately that’s not what happens. It just looks at the group and then goes it merry way.
So if I want to have one control that needs to be validated on multiple conditions, like above and like so many other times in my career, I need to have two required validators for that item. Anyone know if what I want is possible. When my project winds down at the end of the week I hope to look into this some later.