Reputation: 5294
Im working on a bulk email sending app and have a page with a multiline textbox which I am wanting to use as a way of allowing a user to enter the email body text.
I need to format the text within my textbox to HTML, most importantly I need to format linebreaks to HTML, however I cant seem to do this.
The method everyone seems to say to use is:
textOut.Replace("\r\n", "<br />")
But this just does nothing. My Textbox looks like this:
<asp:TextBox runat="server"
ID="txtMailBody"
TextMode="MultiLine"
Width="650"
Height="150"/>
When I enter text in the textbox such as:
Line 1
Line 2
Line 3
It always outputs like
Line 1 Line 2 Line 3
Am I doing something wrong here?
Upvotes: 1
Views: 9901
Reputation: 800
I had the same issue. It worked when I used the following code:
textOut.Replace(System.Environment.NewLine, "<br />")
Upvotes: 1
Reputation: 61
Alle three lines below do it:
TextBox2.Text = TextBox1.Text.Replace(vbLf, "<br>" + vbCrLf)
TextBox2.Text = TextBox1.Text.Replace(vbCrLf, "<br>" + vbCrLf)
TextBox2.Text = TextBox1.Text.Replace(vbNewLine, "<br>" + vbCrLf)
Upvotes: 6
Reputation: 173
There is a function in php named as nl2br you can search for an asp alternative to it.
Upvotes: -1
Reputation: 2075
Try this
txtMailBody.Text.Replace(Environment.NewLine, "<br />")
Hope it helps
Upvotes: 3