在asp.net上验证最小/最大?

时间:2018-10-05 10:00:27

标签: asp.net visual-studio

我必须在asp.net上的代码中验证最小值/最大值...我没有明白..我知道没有错误,但是它没有用,或者我没有注意到错误。我有代码:

 <tr>
    <td>
        <asp:Label ID="label1" runat="server" CssClass="genericLabel" Text="Temperatura Corporea (°C): " />
    </td>
    <td>
        <asp:TextBox ID="tbTemperatura" runat="server" CssClass="smallTextBox"></asp:TextBox>
        <asp:MaskedEditExtender ID="numberFilterMaskedEditExtender" TargetControlID="tbTemperatura" Mask="99.99" MaskType="Number" ErrorTooltipEnabled="True" runat="server" >
        </asp:MaskedEditExtender>
        <asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="numberFilterMaskedEditExtender" ControlToValidate="tbTemperatura" MinimumValue="35" MaximumValue="42" InvalidValueMessage="Temperatura non valida" IsValidEmpty="true" InputDirection="LeftToRight">
         </asp:MaskedEditValidator>
    </td>
</tr

2 个答案:

答案 0 :(得分:1)

在aspx页面顶部注册AjaxControltoolkit 喜欢

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

此处cc1用作AjaxControlToolKit的TagPrefix

<cc1:MaskedEditExtender >一样使用它,而不是<asp:MaskedEditExtender >

<tr>
<td>
    <asp:Label ID="label1" runat="server" CssClass="genericLabel" Text="Temperatura Corporea (°C): " />
</td>
<td>
    <asp:TextBox ID="tbTemperatura" runat="server" CssClass="smallTextBox"></asp:TextBox>
    <cc1:MaskedEditExtender  ID="numberFilterMaskedEditExtender" TargetControlID="tbTemperatura" Mask="99.99" MaskType="Number" ErrorTooltipEnabled="True" runat="server" >
    </cc1:MaskedEditExtender>
    <cc1:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="numberFilterMaskedEditExtender" ControlToValidate="tbTemperatura" MinimumValue="35" MaximumValue="42" InvalidValueMessage="Temperatura non valida" IsValidEmpty="true" InputDirection="LeftToRight">
     </cc1:MaskedEditValidator>
</td>

答案 1 :(得分:0)

正确答案

<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Temperatura non valida" 
forecolor="Red" ControlExtender="numberFilterMaskedEditExtender" controltovalidate="tbTemperatura" 
minimumvalue="35" maximumvalue="42" 
type="Double"></asp:RangeValidator> 

需要在MaskedEditValidator中进行此替换