[英]Only first Label Not Showing on ASP.NET C# page
I have multiple asp.net labels inside 2 update panels. 我在2个更新面板中有多个asp.net标签。 I am handling them all the same but the first one does not show up.
我对它们的处理相同,但是第一个没有显示。 For simplicity sake I have everything happening on one button when in reality the code happens in different places but I stepped through it in Debug and confirmed this is the order.
为了简单起见,我将所有事情都发生在一个按钮上,而实际上代码发生在不同的地方,但是我在Debug中逐步进行了操作,并确认这是顺序。 I am thinking it has to do with the 2 update panels, that a change it UpdatePanel3 doesn't update UpdatePanel2, but not sure.
我认为这与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>
In the code I do the following. 在代码中,请执行以下操作。
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 pops on the screen. LabelError2在屏幕上弹出。 LabelError does not.
LabelError没有。 Using IE, hitting F12 and looking at the DOM LabelError isn't even there.
使用IE,按F12键并查看DOM LabelError甚至不存在。 What am I doing wrong?
我究竟做错了什么? Why won't LabelError show up?
为什么不会出现LabelError?
Taking this theory into account I tried adding UpdatePanel2.Update(); 考虑到这一理论,我尝试添加UpdatePanel2.Update();。 at the end of ButtonShow_Click() This worked.
在ButtonShow_Click()的末尾。 It showed up.
它出现了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.