简体   繁体   English

文本框中的文本不保留其格式

[英]text in the textbox doesnt retain its format

I have asp.net application, in which there is a textbox to enter some text.我有 asp.net 应用程序,其中有一个文本框可以输入一些文本。 The application will send mail to users.该应用程序将向用户发送邮件。 The date whatever they enter in the texbox is the body of the mail.他们在 texbox 中输入的日期就是邮件的正文。 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.我希望结果与我们在带有格式的 texbox 中输入的数据相同。

You can use the replace function on the string:您可以在字符串上使用替换 function :

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.确保您的 email 主体设置为 HTML,这应该可以解决问题。

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.在后面的代码中,您可以使用 C#.net 中的Constants.vbCrLf或 VB.net 中的vbCrLf使其进入下一行,这将显示为您的输入。

Do you have this attribute?你有这个属性吗? .IsBodyHtml = True

write html tags directly on your textarea, this should work.直接在你的文本区域上写 html 标签,这应该工作。 Example: < p>SAMPLE: Testing the issue.< /p> < p>EXAMPLE: Checking for the same.< /p>示例:< p>示例:测试问题。</ p> < p>示例:检查是否相同。</ p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM