我已经声明了变量并从我的 asp 中的下拉列表中填充。但是,在页面加载时,标签不会填充,它们只会在我更改下拉列表中的值时才会填充。因此变量与标签一起使用,而不是最初在页面加载时。
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim strDataCollection As String = ddlDataCollection.Text
Dim strYear As String = DdlYear.Text
Dim strSubject As String = DdlSubject.Text
Dim strTeachingGroup As String = DdlTeachingGroup.Text
Dim strSubgroup As String = ddlSubgroup.SelectedItem.Text
lblHeaderYear.Text = "Year " & strYear
lblHeaderDataCollection.Text = " " & strDataCollection
lblHeaderSubject.Text = " " & strSubject
lblHeaderTeachingGroup.Text = " " & strTeachingGroup
lblHeaderSubroup.Text = " " & strSubgroup
If strTeachingGroup = "Select All" Then
lblHeaderTeachingGroup.Visible = False
Else
lblHeaderTeachingGroup.Visible = True
End If
If strSubgroup = "Select All" Then
lblHeaderSubroup.Visible = False
Else
lblHeaderSubroup.Visible = True
End If
End Sub
我的标签的 asp 是:
<div class="centeronpage">
<asp:Label ID="lblHeaderYear" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderDataCollection" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderSubject" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderTeachingGroup" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderSubroup" runat="server" Text="" CssClass="header"></asp:Label>
</div>
编辑答案
我按照以下建议创建了以下 PreRender。然后我包含 OnPreRender="Page_PreRender"
在其中一个标签元素中,这似乎触发了预渲染。
Protected Sub Page_PreRender(sender As Object, e As EventArgs)
Dim strDataCollection As String = ddlDataCollection.Text
Dim strYear As String = DdlYear.Text
Dim strSubject As String = DdlSubject.Text
Dim strTeachingGroup As String = DdlTeachingGroup.Text
Dim strSubgroup As String = ddlSubgroup.SelectedItem.Text
lblHeaderYear.Text = "Year " & strYear
lblHeaderDataCollection.Text = " " & strDataCollection
lblHeaderSubject.Text = " " & strSubject
lblHeaderTeachingGroup.Text = " " & strTeachingGroup
lblHeaderSubroup.Text = " " & strSubgroup
End Sub
编辑 - DDL 绑定
<asp:Label ID="lblHeaderYear" runat="server" Text="" CssClass="header" OnPreRender="Page_PreRender"></asp:Label>
<asp:Label ID="lblHeaderDataCollection" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderSubject" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderTeachingGroup" runat="server" Text="" CssClass="header"></asp:Label>
<asp:Label ID="lblHeaderSubroup" runat="server" Text="" CssClass="header"></asp:Label>