只有第一个标签未显示在 ASP.NET C# 页面上
本文关键字:NET ASP 第一个 标签 显示 | 更新日期: 2023-09-27 18:36:43
>我在 2 个更新面板中有多个 asp.net 标签。 我正在处理它们,但第一个没有出现。 为了简单起见,我将所有事情都发生在一个按钮上,而实际上代码发生在不同的地方,但我在调试中逐步完成了它并确认这是顺序。 我认为这与 2 个更新面板有关,它 UpdatePanel3 的更改不会更新 UpdatePanel2,但不确定。
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="LabelError" runat="server"
style="float: left" ForeColor="Red"></asp:Label>
....
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="LabelError2" runat="server" Text="Password"
style="float: left" Visible="False"></asp:Label>
<asp:Button ID="ButtonShow" runat="server" Text="Submit"
onclick="ButtonShow_Click" />
</ContentTemplate>
在代码中,我执行以下操作。
protected void ButtonShow_Click(object sender, EventArgs e)
{
LabelError.Visible=true;
LabelError2.Visible=true;
LabelError.Style.Remove("display");
LabelError.ForeColor = System.Drawing.Color.Red;
LabelError2.Style.Remove("display");
if (LabelError.Visible)
{
LabelError.Text="This is Label Error";
LabelError.Style.Add("display", "block");
}
else
{
LabelError.Style.Add("display", "none");
}
if (LabelError2.Visible)
{
LabelError2.Text="This is Label Error2";
LabelError2.Style.Add("display", "block");
}
else
{
LabelError2.Style.Add("display", "none");
}
}
LabelError2 在螢幕上裏裏。标签错误不会。使用IE,点击F12并查看DOM LabelError甚至不存在。我做错了什么? 为什么标签错误不显示?
考虑到这个理论,我尝试添加 UpdatePanel2.Update(); 在 ButtonShow_Click() 的末尾,这奏效了。它出现了。