日期:2014-05-20 浏览次数:20967 次
<asp:TextBox ID="_defineTextBox" runat="server" Width="40px" /> <asp:CustomValidator ID="_defineTextValidator" runat="server" ControlToValidate="_defineTextBox" OnServerValidate="Define_OnServerValidate" Display="Dynamic" ErrorMessage="Must be between 0.00% and 100.00%." ForeColor="Red" SetFocusOnError="True" ToolTip="0.00%-100.00%" >*</asp:CustomValidator>
protected void Define_OnServerValidate(object source, ServerValidateEventArgs args) { bool valid = true; decimal output = -1.0M; if (!string.IsNullOrWhiteSpace(args.Value)) { var amount = args.Value.Replace(CurrencyTye, ""); var value = decimal.TryParse(amount, out output) ? output : -1.0M; if (value < 0M || value > 100.00M) valid = false; else valid= true; } args.IsValid = valid; }