2016-04-04 14 views
0

İki metin kutusu ve iki karşılaştırıcı var. Birinin diğerinden daha düşük olmasını istiyorum. Her iki metin kutusu da gerekli validasyona sahip olmalıdır.Boş hedef denetiminde CompareValidator atlama onayı nasıl yapabilirim?

textboxs biri olan, doğrulayıcı için kod aynı zamanda metnin bir int ve bir olup olmadığını kontrol etmek iyi bir fikir olacağını çünkü

<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

Ben CompareValidator kutunun dışında bu senaryoyu işleyebilir olup olmadığını bilmiyorum. Bunun yerine bir CustomValidator denetimi kullanmayı düşündünüz mü? –

+0

Yaptım, ancak işe yaramazdı, ve bunu CompareValidator'da ele almanın bir yolu olabileceği görünüyor. – Jmassa

cevap

0

Bir CustomValidator iyi yaklaşım olduğunu kabul olduğunu dize. sizin aspx olarak

:

<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"/> 

Kodda:

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

Teşekkürler, ben bunu kullanarak sona erdi! – Jmassa