![](/img/trans.png)
[英]ASP.net C# page, 2 DropDownList on page with 2 onSelectedIndexChange only the first one fires
[英]Only first Label Not Showing on ASP.NET C# page
我在2个更新面板中有多个asp.net标签。 我对它们的处理相同,但是第一个没有显示。 为了简单起见,我将所有事情都发生在一个按钮上,而实际上代码发生在不同的地方,但是我在Debug中逐步进行了操作,并确认这是顺序。 我认为这与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在屏幕上弹出。 LabelError没有。 使用IE,按F12键并查看DOM LabelError甚至不存在。 我究竟做错了什么? 为什么不会出现LabelError?
考虑到这一理论,我尝试添加UpdatePanel2.Update();。 在ButtonShow_Click()的末尾。 它出现了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.