text in the textbox doesnt retain its format

天涯浪子 提交于 2019-12-24 19:05:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!