Reputation: 131
I dont know why I'm unable to assign text to a label, if I'm using a textbox then it does it fine...
my xaml:
<Label Name="TimerLabel" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="1" />
xaml.cs:
TimerLabel.Text = "sadssa";
https://i.sstatic.net/hpjY1.jpg
I have the right references I believe... I'm able to assign text to the label fine directly from the .xaml using Content="texthere" but I cant seem to assign text via the code. (Tried TimerLabel.Content = "asds"; but no result https://i.sstatic.net/m7UyU.jpg)
Upvotes: 2
Views: 4206
Reputation: 331
In my situation I'm using nop commerce so the @Html.LabelFor()
needed to be replaced with @html.NopLabelFor()
I also had to add the following reference @using Nop.Web.Framework
Upvotes: 0
Reputation: 1016
This can happen if you have the incorrect dll referenced at the top of your .cs file. For example I had incorrectly referenced:
using System.Reflection.Emit;
When really I needed
using System.Web.UI.WebControls;
Upvotes: 0
Reputation: 533
Assign the Content
property of the label. Or use TextBlock
instead.
TextBlock
is roughly the same as a Label
from WinForms.
As per MSDN:
The TextBlock control is the primary element for displaying text in Silverlight based applications.
Provides a lightweight control for displaying small amounts of text...
You might want to consider a TextBlock depending on how your using it. Again per MSDN:
A Label control displays a caption, required field indicator, and validation error indicator to the user. It is typically used together with an input control, such as a TextBox. If you do not need to display required field or validation indicators, you can use the TextBlock control instead.
Upvotes: 3
Reputation: 4891
Label able to contain not only text, so use Content
property instead.
Upvotes: 0