tags:

views:

80

answers:

7

I want to show new line in label using c# but it's not working in every browser.

I want to show in xml format in browser.

My Code as below

lblSaleData.Text ="" + "\n" + "" + eml + "" + "";

+3  A: 

Try This It ll work in most browser..

lblSaleData.Text = "&lt;Sales&gt;" + "<br/>" + 
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;eml&gt;" + eml + 
"&lt;/eml&gt;" + "<br/>"+ "&lt;/Sales&gt;";
Umakanta.Swain
SO swallowed your BR's! I'll try fix :)
leppie
+2  A: 

<br /> for line breaks.

Ruel
+1  A: 
SWeko
How the browser might choke on the <sales> and <eml> tags is another story :)
SWeko
+1  A: 

If you want an HTML line break, use <br /> as suggested.

If what you want is to show nicely laid-out HTML source in a label, use System.Environment.Newline. I normally stick it as a static readonly string NL at the top of a file.

Lunivore
It ll not work in some browsers . I ve tried too.
Umakanta.Swain
Meh, stop using IE6. It's not worth the hassle you'll have supporting it.
Lunivore
+1  A: 

Looks like you're printing out XML on the screen, right? The Label control is automatically HTML-Encoding your text, so that the angle brackets aren't treated as html elements.

The newline character doesn't show on the screen, because <br /> is the correct html element for a newline.

James McCormack
Yes Buddy......... Thats what the question was like that...........
Umakanta.Swain
A: 

I'd use:

lblSaleData.Text =String.Format("&lt;Sales&gt;<br />&lt;eml&gt;{0}&lt;/eml&gt;&lt;/Sales&gt;",eml);
elsni
A: 

"Line1" + "< br / >" + "Line 2" will do the trick.

Andrei Bularca