Answered by:
Label does not display text set in code behind

Question
-
User1269672279 posted
I have a web form that is driving me mad - a label on the form is not displaying text, and I can't see why.
The form has a master page, and I have tested what I think is identical code on another web form using the same master page and it works just fine. Nowhere in the code is the label set invisible, nor is it set to "". The label is in an update panel, but it won't even set to a value on Page_Load.
Here is the page:
<asp:Content ID="Content4" ContentPlaceHolderID="PageContent" Runat="Server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div class="w3-container w3-white w3-padding-16 w3-row"> <h1 class="w3-center"><asp:Label ID="lblHeading" runat="server" Text=""></asp:Label></h1> </div> <div class="w3-container w3-white w3-padding-16 w3-row w3-center"> other divs and stuff... </div> <div class="w3-container w3-white w3-padding-16 w3-row w3-center"> <div class="w3-col m4 l5 w3-orange w3-padding-small"> <h3 class="w3-center"><asp:Label ID="lblOpening" runat="server" Text=""></asp:Label></h3> <div class="w3-row "> <asp:Label ID="lblWidth" runat="server" Text="" Width="100px"></asp:Label> <asp:TextBox ID="txtWidth" runat ="server" OnTextChanged="txtWidth_TextChanged" AutoPostBack="true" width="100px" CssClass="w3-center"></asp:TextBox> m </div> <div class="w3-row "> <asp:Label ID="lblHeight" runat="server" Text="" Width="100px"></asp:Label> <asp:TextBox ID="txtHeight" runat ="server" OnTextChanged="txtHeight_TextChanged" AutoPostBack="true" width="100px" CssClass="w3-center"></asp:TextBox> m </div> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="txtWidth" EventName="TextChanged" /> <asp:AsyncPostBackTrigger ControlID="txtHeight" EventName="TextChanged" /> <asp:AsyncPostBackTrigger ControlID="cboSelectedSize" EventName="SelectedIndexChanged" /> </Triggers> <ContentTemplate> <div class="w3-row">here is the start of the label <asp:Label ID="lblSuggestedSize" runat="server" Width="50%" Text=""></asp:Label> here is the end of the label <asp:Button ID="btnUpdate" runat="server" Text="Update" /> </div> </ContentTemplate> </asp:UpdatePanel> </asp:Content>
And here is the Page Load (VB):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim SCUser As New clsSCUser Dim PageTranslations As New clsPageTranslation Dim SCProduct As New clsProduct SCUser = Session("SCUser") Try If Not SCUser.LoggedOn Then Response.Redirect("login.aspx") Else PageTranslations.PageNumber = 16 'Bayscreen Configurator is page 16 PageTranslations.Language = SCUser.CurrentLanguage 'as selected by the user on the menu system, or their default at the start lblHeading.Text = PageTranslations.TextItem(1) 'Bayscreen Configurator lblDetails.Text = PageTranslations.TextItem(2) 'Specific Details lblOpening.Text = PageTranslations.TextItem(3) 'Opening Dimensions lblWidth.Text = "Width" lblHeight.Text = "Height" lblSelectedSize.Text = "Selected Size: " imgProduct.ImageUrl = "images/products/" & strProductNumber & ".jpg" 'other lines of code... End If Catch ex As Exception Response.Redirect("login.aspx") End Try End If End Sub
All the other labels load properly and have their text displayed except lblSelectedSize - and I cannot work out why. Can you spot what I have done wrong?
Thanks,
Dave
Friday, September 6, 2019 3:40 PM
Answers
-
User475983607 posted
What is the name or ID of the label? I found this label in the markup up which is inside an UpdatePanel.
<div class="w3-row">here is the start of the label <asp:Label ID="lblSuggestedSize" runat="server" Width="50%" Text=""></asp:Label> here is the end of the label <asp:Button ID="btnUpdate" runat="server" Text="Update" /> </div>
The shared code snippet does not set the lblSuggestedSize label. Where are you setting the label?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, September 6, 2019 5:47 PM -
User288213138 posted
Hi bayscreendave,
All the other labels load properly and have their text displayed except lblSelectedSizeAccording to your description, I didn't find lblSelectedSize label in your aspx page.
Please post the code related to lblSelectedSize label.
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, September 9, 2019 2:57 AM
All replies
-
User475983607 posted
What is the name or ID of the label? I found this label in the markup up which is inside an UpdatePanel.
<div class="w3-row">here is the start of the label <asp:Label ID="lblSuggestedSize" runat="server" Width="50%" Text=""></asp:Label> here is the end of the label <asp:Button ID="btnUpdate" runat="server" Text="Update" /> </div>
The shared code snippet does not set the lblSuggestedSize label. Where are you setting the label?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, September 6, 2019 5:47 PM -
User288213138 posted
Hi bayscreendave,
All the other labels load properly and have their text displayed except lblSelectedSizeAccording to your description, I didn't find lblSelectedSize label in your aspx page.
Please post the code related to lblSelectedSize label.
Best regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, September 9, 2019 2:57 AM -
User1269672279 posted
Thanks both! I'm glad you spotted what I was too tired to see on Friday afternoon. I have two labels here: one called lblSuggestedSize and one called lblSelectedSize and I managed to get the two confused in my head. The code will do a calculation based on the sizing parameters supplied and suggest a size of product suitable for the customer' needs - this goes in lblSuggestedSize. lblSelectedSize is a heading next to a drop-down list where the customer can select a product size which may or may not be the same as suggested.
I was testing this part of the code before starting the calculation and building the other controls on the page and I did not see the error.
Thank you so much for you help.
Dave
Monday, September 9, 2019 7:41 AM