问题
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.
回答1:
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.
回答2:
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.
回答3:
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>
来源:https://stackoverflow.com/questions/6124524/text-in-the-textbox-doesnt-retain-its-format