Solved

Html Text Box

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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