Ricardo Deano
Ricardo Deano

Reputation: 2819

Why does Environment.NewLine not work on .net label?

I have a solution to this little problem, but I'm trying to get my head around what is happening.

I have a website with a label:

  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

And on Page_load I have:

 protected void Page_Load(object sender, EventArgs e)
    {
         Label1.Text = "It is now: " + Environment.NewLine + DateTime.Now.ToShortTimeString();
    }

Why does this not produce a new line / carriage return?

I have a solution but I'm just trying to grasp what is going on and why this doesn't work.

Upvotes: 1

Views: 3973

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460238

A line break in html is <br>:

Label1.Text = "It is now: <br>" + DateTime.Now.ToShortTimeString();

Upvotes: 2

Related Questions