2009-08-12 10 views
0

Y at-il un moyen pour moi aussi de boucler tous les contrôles sur un panneau asp.net, et pour chacun des contrôles vérifier le type pour voir si elle est de asp type TimeInput?JavaScript - ASP.net - Boucle à travers tous les contrôles sur un panneau asp

La JS a besoin basiquement de reproduire ce Serverside Code VB.net

'this is checking that something has been entered into at least one of the time input boxes 
Protected Sub valCusAllTextBox_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles valCusAllTextBox.ServerValidate 
    'When the Save or Submit button is clicked the Page.IsValid() command causes the "valCusAllTextBox" custom validator control 
    '(which was dragged on to the page) to call this event - where we do our customised error checking 
    args.IsValid = False  'args.IsValid is a system function 
    'check all controls within the Overtime Claim panel 
    For Each ctrl As Control In pnlOvertimeClaim.Controls 
     If TypeOf ctrl Is TimeInput Then 
      If CType(ctrl, TimeInput).TimeInMinutes <> 0 Then 
       args.IsValid = True 
       Exit For 
      End If 
     End If 
    Next 
    If txtOnCallAllow.Text.Trim() <> "" Then 
     args.IsValid = True 
    End If 
    If txtMealAllow.Text.Trim() <> "" Then 
     args.IsValid = True 
    End If 
End Sub 

Répondre

2

vous pouvez utiliser ce script pour trouver un contrôle spécifique à partir du panneau, script mis à la fin de la page,

<script type="text/javascript" language="javascript"> 
var pnl = document.getElementById('pnl') 
var array = pnl.getElementsByTagName("a"); 
for (var n = 0; n < array.length; ++n) { 
    alert("anchor"); 
} 
var array = pnl.getElementsByTagName("img"); 
for (var n = 0; n < array.length; ++n) { 
    alert("Image"); 
} 

Comme ceci est votre panneau et que vous voulez itérer contrôle spécifique.

<asp:Panel runat="server" ID="pnl"> 
     <a id="sd" href=""></a> 
     <img src="" /> 
     <a id="A1" href=""></a> 
    </asp:Panel> 
Questions connexes