0

I have asp.net application, in which there is a textbox to enter some text. The application will send mail to users. The date whatever they enter in the texbox is the body of the mail. The issue the formatting is not retained in the outcome of the mail. It's cumbersome.

For example I enter following text in textbox :

SAMPLE : Testing the issue.

EXAMPLE : Checking for the same .

the outcome of mail look like following :

sample : testing the issue.example : checking for the same.

I want the outcome to be same as the data we enter in the texbox with formatting.

4
  • In which language r u writting ur code part VB or C# Commented May 25, 2011 at 12:38
  • I don't know anything about asp.net, but you need to use a function that converts newline characters \n to HTML newlines <br>
    – bigblind
    Commented May 25, 2011 at 12:39
  • Is the mail HTML formatted? If so, your carriage returns probably need to be converted to line break tags.
    – David
    Commented May 25, 2011 at 12:39
  • A function to convert newlines to HTML breaks is in my answer below.
    – James
    Commented May 25, 2011 at 12:52

3 Answers 3

2

You can use the replace function on the string:

string mystring = textbox.Text;
mystring = mystring.Replace(System.Environment.NewLine, "<br />");

Make sure that your email body is set to HTML, and that should do the trick.

0
0

In code behind you can use Constants.vbCrLf in C#.net or vbCrLf in VB.net for making it to take the next line, which will appear as ur input.

2
  • HOW TO USE IT DO I HAVE TO REPLACE THE TEXTBOX.TEXT WITH vBCRLF
    – chaitanya
    Commented May 25, 2011 at 12:50
  • No, u are appending the text which is entering in the text box to be displaying it in the mail right, there after the first text box's text u have to concat this one according to ur language. Commented May 25, 2011 at 12:52
0

Do you have this attribute? .IsBodyHtml = True

write html tags directly on your textarea, this should work. Example: < p>SAMPLE : Testing the issue.< /p> < p>EXAMPLE : Checking for the same .< /p>

2
  • I HAVE SET .ISBODYHTML = TRUE, USING c#
    – chaitanya
    Commented May 25, 2011 at 12:49
  • Now write html tags directly on your textarea, this should work. Example: <p>SAMPLE : Testing the issue.</p> <p>EXAMPLE : Checking for the same .</p>
    – Otto
    Commented May 25, 2011 at 12:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.