简体   繁体   English

JavaScript-ASP.net-遍历ASP面板上的所有控件

[英]JavaScript - ASP.net - Loop through all controls on an asp pannel

Is there any way for me too loop though all controls on an asp.net pannel, and for each of the controls check the type to see if it is of asp type TimeInput? 我有什么办法也可以循环遍历asp.net面板上的所有控件,对于每个控件,请检查其类型以查看其是否为TimeTime类型的asp类型?

The JS basicly needs to replicate this serverside VB.net code JS基本上需要复制此服务器端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

you can use this script to find specific control from the panel, Put script at the end of 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");
}

Like this is your panel and you want to iterate specific control. 像这样的面板,您想迭代特定的控件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM