Last post Feb 28, 2012 04:11 PM by superguppie
Feb 23, 2012 08:54 PM|danwilliams00|LINK
I have a webpage that displays a description for a product in an ASP:LABEL field. The label is assigned in the .aspx.cs page behind. The description field can be up to 2000 characters but at the moment there is no formatting to the text that is displayed.
Can you tell me how I can add carriage returns to the text? I have done some research and have found out that "/n" can be used but I do not how to use it. Can anybody help me?
<td colspan="2" class="td_style2">
<asp:Label CssClass="padded" ID="descriptionLabel" runat="server" Text="Label"></asp:Label></td>
pd = CatalogAccess.GetProductDetails(productId);
descriptionLabel.Text = pd.Description;
Feb 23, 2012 09:03 PM|AZMatt|LINK
You can use <br /> for your line return in a Label control.
Feb 24, 2012 02:30 PM|superguppie|LINK
If you set width and white-space:pre-wrap on the style. That will keep the width static, and make the text wrap on spaces.
Feb 24, 2012 02:40 PM|Vipindas|LINK
According to line break in text area is "\n"
so you can replace some thing like this
Text1.Text = pd.Description.Replace("<br />", "\n");
Feb 25, 2012 11:25 AM|danwilliams00|LINK
I have put the code below into Product.aspx.cs file but it still doesn't work. I have manually added \n to the description field in the database table where I want the carriage return but it just displays \n on the webpage.
descriptionLabel.Text.Replace("\n", "<br />");
descriptionLabel.Text = pd.Description.Replace("<br />","\n");
Can you help me resolve the problem?
Feb 25, 2012 11:55 AM|Vipindas|LINK
Note that you don't need to insert new line manually. When you enter a text into a textarea and press enter it will automatically creates a line break. But the text area line break will not support in html. New line in html is represented by the <br /> tag.
descriptionLabel.Text = pd.Description.Replace(Environment.NewLine, "<br />");
Feb 25, 2012 06:52 PM|basheerkal|LINK
set TextBox. Mode = Multiline and Try
TextBox1.Text = "aaa" & vbCrLf & "bbb" & vbCrLf & "ccc"
Feb 27, 2012 02:06 PM|AZMatt|LINK
I think you need to add an additional back-slash to the string in descriptionLabel.Text.Replace("\\n", "<br />"); C# treats this as an escape sequence.
Feb 28, 2012 04:11 PM|superguppie|LINK
Ok, my last post didn't answer the question. Sorry. Misread it.
Have you tried using a pre tag instead of a Label? pre tags preserve \n in text. No need to replace it with br tags.