2016-04-04 20 views
0

私は2つのテキストボックスと2つの比較検証を持っています。私は一方が他方よりも低くなるようにしたい。どちらのテキストボックスも必要な検証が必要です。空のターゲットコントロールでCompareValidatorのスキップ検証を行うにはどうすればよいですか?

textboxsのいずれかのコードとそのバリデータは、私はまたテキストはintではないことを確認するために良いでしょうので、のCustomValidatorが最善のアプローチであることに同意

<asp:TextBox runat="server" ID="txtRiesgo_Total_Des" MaxLength="18" Visible="false"></asp:TextBox> 
        <asp:CompareValidator runat="server" ID="compareRiesgoDesdeHasta" ControlToValidate="txtRiesgo_Total_Des" 
         Font-Size="XX-Small" Type="Double" ControlToCompare="txtRiesgo_Total_Has" ErrorMessage="Desde < Hasta<br>" 
         Operator="LessThan" Display="Static"> 
        </asp:CompareValidator> 
+0

私はこのCompareValidatorは、箱から出して、このシナリオを扱うことができるかどうかわかりません。代わりにCustomValidatorコントロールの使用を検討しましたか? –

+0

私はしましたが、それを動作させることができず、CompareValidatorでこれを処理する方法があるようです。 – Jmassa

答えて

0

です文字列。

あなたのASPXで

:背後にあるあなたのコードで

<asp:CustomValidator ID="cvCompareInt" runat="server" 
ErrorMessage="Must be lower" 
ControlToValidate="txtRiesgo_Total_Des" 
OnServerValidate="Riesgo_Total_Des_Validate" 
Display="Dynamic" > 
</asp:CustomValidator> 
<asp:TextBox runat="server" ID="txtRiesgo_Total_Des" MaxLength="18" ></asp:TextBox> 
    <asp:TextBox runat="server" ID="txtRiesgo_Total_Has" MaxLength="18"></asp:TextBox> 
    <asp:Button runat="server" id="btnSubmit" Text="submit"/> 

protected void Riesgo_Total_Des_Validate(object source, ServerValidateEventArgs args) 
{ 
    int lowerNum; 
    int higherNum; 
    bool lower = int.TryParse(txtRiesgo_Total_Des.Text, out lowerNum); 
    bool higher = int.TryParse(txtRiesgo_Total_Has.Text, out higherNum); 
    if (lower && higher) 
    { 
    if (lowerNum >= higherNum) 
     { 
      args.IsValid = false; 

     } 

    } 
} 
+1

ありがとう、これは私が使い終わったものです! – Jmassa

関連する問題