开发者

ASP.NET Validate text box that already has a value in it

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜