?
Solved

Html Text Box

Posted on 2009-06-30
3
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

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 23

Accepted Solution

by:
Snarf0001 earned 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 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