I have a textbox that displays the total cost o开发者_StackOverflowf the shopping cart.
When the page loads the value in the shopping cart is set at 0.00. When a user adds an item to the cart the textbox automatically displays the new total.
How can I validate this text box to stop someone clicking on the buy button and therefore purchase items with the value of 0.00?
I tried using a compare validator but it was a mess!
asp:CompareValidator ID="cprPriceTotalCost" runat="server" Display="Dynamic"
ControlToValidate="tbxPriceTotalCost" Operator="GreaterThan"
Type="Currency" ValueToCompare="0.00"
Ideally you shouldn't be having a text input for that field. It should just be a label i.e. non-editable readonly text. That field should be solely for display purpose.
And again when you manipulate that field in the code-behind you should not take the Total value from that label but do calculation from your server-side values. Imagine those values being manipulated on client-side.
To answer your question: You can use CustomValidator control.
精彩评论