簡體   English   中英

ASP.NET C#頁上僅未顯示第一個標簽

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM