Asp: Label not showing if visible is true?

I have a simple web form that has several lists and a search button. When a button is pressed, it returns a DataSet. If the data set contains records, I set the asp: label, which is initially set to false, to true, but this does not happen. If there are records in the dataset and the visible property is set to true, the label is still not displayed.

I also tried putting a shortcut and a couple of other controls in the html table and setting the runat = "server" attribute in the table and changing the visibility of this, but it also does not appear.

Here is the aspx code:

<table> <tr> <td> <asp:Label ID="lblSortBy" runat="server" Text="Sort By:" Visible="false"> </asp:Label> <asp:DropDownList ID="ddlSortBy" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged"> <asp:ListItem Value="Gross">Gross</asp:ListItem> <asp:ListItem Value="Population">Population</asp:ListItem> </asp:DropDownList> </td> </tr> </table> 

The following is a simplified code when a button is clicked:

 public void GetData() { DataView dv = GetReportData().DefaultView; if(dv.ToTable().Rows.Count > 0) { lblSortBy.Visible = true; } else { lblSortBy.Visible = false; } } 

I have a couple of update panels around some ListBoxes and GridView, but not Label and Dropdown. Will this cause a problem?

I did a test, I set the label that was in the update panel to false if the entries were found and the label disappeared, so it works if it is in the update panel.

+4
source share
6 answers

If I'm not mistaken, your shortcut must exist in the update panel, because as far as a static HTML page is concerned, the one and only time your current shortcut exists does not appear. You will need to reload the entire page to make it visible again.

+5
source

If the button is inside an UpdatePanel, then a table, Label, etc. must also be inside the UpdatePanel for updating. Otherwise, only the UpdatePanel is updated at the click of a button (this is called partial page rendering ).

So, if the button is in UpdatePanel, you have two options to solve the problem:

  • put table, shortcut, DropDownList etc. in the same UpdatePanel
  • or put them in another UpdatePanel and set the UpdateMode parameter of this property to Always so that it is updated even if the postback was triggered by the control within another UpdatePanel.

See this page on MSDN for more details.

+3
source
  • You just need runat = "server" on the label itself; although Visible should be True.
  • Make sure you add ForeColor to avoid mixing in w / background.
  • Debugging to ensure that your shortcut has content, and not in another Visible = False control.
0
source

I assume you will hide ddl too if there is no data. You tried to place the panel around both of them and set its visibility to true

if you return the rows, and your button is in the updated panel, then your label and ddl in this update panel also

0
source

If the table changes the visibility and is the parent container of the label, I do not think that it is necessary to change the visibility of the label in general, since it should always be visible.

0
source

thanks for this really useful, put Lable on the update panel.

  <ContentTemplate> <table> <tr> <td> <asp:LinkButton ID="LinkNM" runat="server" Text="Learn>" BackColor="Transparent" style=" color: #6699FF;text-decoration-color:none;border:none;font-size:x-large" OnClick="LinkNM_Click"/> &nbsp;&nbsp;&nbsp; <asp:Label ID="lblChapterName" runat="server" BackColor="Transparent" style=" color: #6699FF;text-decoration-color:none;border:none;font-size:x-large" ></asp:Label> </td> </tr> </table> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="btnFileUpload" /> </Triggers> </asp:UpdatePanel> 
-2
source

All Articles