【发布时间】:2016-01-21 06:48:25
【问题描述】:
我有一个文本框,允许用户用小数键入值。如何在文本框中设置只能输入2位小数。现在,用户可以输入超过 2 个小数位。下面是文本框的代码:
<td><b>Payment Amount:</b></td>
<td colspan="2">
<asp:TextBox ID="txtPayment" runat="server" Enabled="true" CssClass="form-control"/>
<asp:RequiredFieldValidator ID="rfvPayment" runat="server" ControlToValidate="txtPayment" ValidationGroup="SubmitGroup" Display="Dynamic" ErrorMessage="* Please fill in this section" />
<asp:RangeValidator ID="rgPayment" runat="server" ControlToValidate="txtPayment" Display="Dynamic" Type="Double"/>
</td>
对于文本框,在 id=rgPayment 上,我使用 rangevalidator 来验证值。 代码如下:
protected void lnkbtnB2CProceed_Click(object sender, EventArgs e)
{
rgPayment.MaximumValue = "30000";
rgPayment.MinimumValue = "1";
txtPayVia.Text = "Retail Banking";
if (CheckAmount())
{
Proceed(Resources.Default.FPXMsgTokenB2C);
trSupportedChannel.Visible = false;
}
}
protected void lnkbtnB2BProceed_Click(object sender, EventArgs e)
{
rgPayment.MaximumValue = "1000000";
rgPayment.MinimumValue = "2";
txtPayVia.Text = "Corporate Banking (FPX)";
if (CheckAmount())
{
Proceed(Resources.Default.FPXMsgTokenB2B);
trSupportedChannel.Visible = false;
}
}
谢谢
【问题讨论】:
-
考虑加一个问号,我看了好几遍才发现你在问问题。