Solved

Html Text Box

Posted on 2009-06-30
3
194 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
Comment Utility
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
Comment Utility
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
Comment Utility
That is very useful.  Thanks a lot!

Wing
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now