Solved

Html Text Box

Posted on 2009-06-30
3
230 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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: …

719 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