Solved

Html Text Box

Posted on 2009-06-30
3
213 Views
Last Modified: 2012-05-07
HI

I want to create a comments section under some pages in our website. The stumbling block seems to be the text input. The main body of the content needs to be just text without any formatting.  However when it gets displayed on the page after being saved to the db it needs to be html formatted with <p> tags.

Is there any control out there that will accept text and format into very basic html (p tags and br tags only.

I have used fckeditor but this will basically allow anything to be pasted into it including links - we dont want this.

Wing
0
Comment
Question by:WingYip
  • 2
3 Comments
 
LVL 22

Expert Comment

by:Snarf0001
ID: 24745678
I don't think you need a control to do this, a few simple replaces on postback should get you where you want.  All you really need to do is scan the text for line breaks, and replace them with html equivelent, ie...

string formattedText = textBox.Text.Replace(Environment.NewLine, "<br />");
0
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 50 total points
ID: 24745753
Here's a better version, any double line breaks will be wrapped in <p> tags, while single ones will just have a <br /> appended:

string formatted = String.Format("<p>{0}</p>", txtComments.Text.Replace(Environment.NewLine + Environment.NewLine, "</p><p>"));
formatted = formatted.Replace(Environment.NewLine, "<br />");
0
 
LVL 1

Author Comment

by:WingYip
ID: 24746586
That is very useful.  Thanks a lot!

Wing
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question