在同一页面上出现两次的用户控件需要javascript的唯一div id

时间:2017-03-27 22:43:37

标签: javascript asp.net .net vb.net

我有一个在div中显示消息的javascript。我传入一个ID,它就知道在哪里显示消息。

这些div位于页面上多次出现的用户控件中。 该消息仅显示在第一个div上(因为它是第一个匹配的ID .InamingContainer在这里没有帮助,因为javascript仍会扫描整个页面并找到第一个匹配的ID。

最好的方法是什么?我是否必须为每个UserControl动态设置ID?有没有办法我可以拥有多个消息div并只是从后面的UserControl代码启用/禁用它们来控制每个UserControl中显示哪些?

的Javascript

ADODB

}

在我的UC中

ADODB

如何从后面的代码中调用javascript

Sub AppendRecords(NewRecords As ADODB.Recordset, OriginalRecords As ADODB.Recordset)
    Dim AllFieldsMatch As Boolean
    Dim Iterator       As Integer
    Dim ActiveField    As Field
    Dim FieldCount     As Integer
    Dim FieldNames()   As String
    Dim FieldValues()  As Variant

    FieldCount = NewRecords.Fields.Count

    For Iterator = 0 To FieldCount - 1
        If NewRecords.Fields(Iterator).Name <> OriginalRecords.Fields(Iterator).Name Then
            AllFieldsMatch = False
            Err.Raise 10001, "AppendRecords", "Field names are not matching."
        End If
    Next

    For Iterator = 0 To FieldCount
        If NewRecords.Fields(Iterator).Type <> OriginalRecords.Fields(Iterator).Type Then
            AllFieldsMatch = False
            Err.Raise 10002, "AppendRecords", "Field Types are not matching."
        End If
    Next
    If NewRecords.EOF And NewRecords.BOF Then
        Err.Raise 10003, "AppendRecords", "There are no records in new Recordset."
    End If

    Iterator = 0
    ReDim FieldNames(Iterator To FieldCount - 1)
    ReDim FieldValues(Iterator To FieldCount - 1)

    For Each ActiveField In NewRecords.Fields
        FieldNames(Iterator) = ActiveField.Name
    Next

    While Not NewRecords.EOF
        For Each ActiveField In NewRecords.Fields
            FieldNames(Iterator) = ActiveField.Value
        Next

        OriginalRecords.AddNew FieldNames, FieldValues

        NewRecords.MoveNext
        'LogCompletedJob "GetCoverageTable"  'Ignore for now
    Wend
End Sub

1 个答案:

答案 0 :(得分:1)

您可以使用Panel Server控件。 ASP.Net确保所有服务器控件都具有唯一ID。

例如,

<asp:Panel runat="server" ID="Panel1" CssClass="messagealert alert alert-small">
</asp:Panel>

呈现HTML

<div id="Panel1" class="messagealert alert alert-small">
</div>