The objective: Display a list of prices for various admission tickets. Some tickets in the list are free (i.e. children under 3), some items are not admission tickets (e.g. venue guide, etc.).
Business rule: Bookings cannot be made for any less than 15 paying visitors.
I have the following Repeater control which is populated by a stored procedure returning a DataSet of all the 'tickets' (see above) available for the date the user has chosen to visit the venue:
1 <asp:Repeater ID="rptrTickets" runat="server" OnItemDataBound="BindOnChangeEvents">
2 <ItemTemplate>
3 <tr class="item" id=<%# Eval("TicketTypeID") %>>
4 <td><%# Eval("Product") %></td>
5 <td runat="server" id="Price"><%# Eval("Price") %></td>
6 <td>
7 <asp:Literal runat="server" ID="TicketType" Visible="false" Text=<%# Eval("TicketTypeID") %>></asp:Literal>
8 <asp:TextBox ID="txtQty" MaxLength="3" style="width: 3em;" runat="server" ></asp:TextBox>
9 <asp:RangeValidator ID="rngvTxtQty" MinimumValue="0" MaximumValue="999" ControlToValidate="txtQty" EnableClientScript="true" Type="Integer" runat="server" Text=" *"></asp:RangeValidator>
10 <!-- Need to find a way to disallow white space
11 <asp:RegularExpressionValidator ID="revTxtQty" ControlToValidate="txtQty" runat="server" ValidationExpression="^\d+$" Text=" *"></asp:RegularExpressionValidator>
12 -->
13 </td>
14 <td>£<asp:Label ID="lblTotal" runat="server" enableviewstate="true" Text="0.00">0.00</asp:Label></td>
15 </tr>
16 </ItemTemplate>
17
18 </asp:Repeater>
19 <asp:ValidationSummary ID="ValidationSummary1" HeaderText="Please enter only numbers in the marked (*) fields:" runat="server" />
I am trying to figure out how i can do a server side check (client side will need to be in place as well, eventually) to enforce the business rule (as above).
I have already found a method of looping through all the repeater items and determining the quantity of tickets per ticket type, thus allowing me to determine whether the input meets the requirement or not. However, this is occurring in response to a button click event, so the page as already been through the validation stage of the page lifecycle.
What i would like to be able to do is, if the business requirement is not met, change the HeaderText of the ValidationSummary control (or even a new validation control, or even a label, doesn't matter) to display an error message, and then basically point the user back to the same page again with the updated error message.
So in short, how can i perform this kind of server side validation?
Where the result depends on the sum of the contents of an unknown number of text boxes in a repeater control and where the content of only some of the text boxes are to be included in the summation.
Any thoughts/suggestions/advice for better approach would be most appreciated!
Thanks in advance,
lj.