Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

This example demonstrates how to print or display the contents of the MultiLine TextBox in a Label Control and retain its line breaks.

Basically MultiLine Mode of TextBox uses Environment.NewLine to create a new line. So if you try to display the values of TextBox in  a Label Control or print it on the page and retain its position then you can replace the  Environment.NewLine with <BR> Tag since Label control doesn't recognized Environment.NewLine.

Here's a sample demo  below for your reference:

ASPX

<asp:TextBox ID="TextBox1" runat="server" Height="300px" Width="300px"
                           TextMode="MultiLine"/>

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
                         Text="Print to Label Control"/>
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Height="300px" 
                       Width="300px"/>

RELEVANT CODES

 
protected void Button1_Click(object sender, EventArgs e){        
     Label1.Text = TextBox1.Text.Replace(Environment.NewLine, "<BR/>");
}
 
and here's the page output below

Technorati Tags: ,
Posted on Tuesday, February 17, 2009 5:04 PM ASP.NET | Back to top


Comments on this post: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks

# re: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks
Requesting Gravatar...
This doesn't work for me.
I have a multiline textbox, and whenever i tried replacing Environment.NewLine with "<BR/>" but to add an agony it doesnt even replace the strings. Are you sure its Environment.NewLine only.
Left by Nirman Doshi on Feb 24, 2009 11:17 PM

# re: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks
Requesting Gravatar...
Works great. Thanks for the knowledge.
Left by Dennis on Mar 06, 2010 3:03 AM

# re: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks
Requesting Gravatar...
Simple and efficient, helped me a lot. Thank you
Left by Saša Dragičević on May 03, 2011 6:52 PM

# re: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks
Requesting Gravatar...
This worked for me. thanks a bunch...
Left by Mario on Jun 06, 2011 10:50 PM

# re: Display Contents of MultiLine TextBox to Label Control and Retain its Line Breaks
Requesting Gravatar...
Good Job ! It works .
Left by Tejalal Choudhary on Aug 06, 2012 11:08 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net