Hello.
As a new learner to ASP.Net I was curious to make a small blog machine. A simple application, where I add a title, upload an image and put some text.

I did that. To display it, I used an editbox for title, another for description and an image control for displaying image.

Ok. Everything looked fine. Except for the description. All the text I wrote on the Add post page, got mixed. I wrote many paragraphs, but during display everything was merged together without any spaces between different paragraph.

So, all I could understand was that, my database didnot save the formatting.

So my question is, should I add a post in HTML format, so my database could store all the formatting details like Enter, Paragraph etc. And also Fonts, color, sizes etc If I use an html editor for that?

Can anyone guide me what is the best practice to do this?

Thanks in Advance.

When you postback a form to the codebehind, all the formatting is there (except font and color).
But for some reason the database/datatype sometimes has problems retaining those.

When I ran into this problem on a project once, I simply read all the text from the textbox/textarea into a string variable and at the same time replace all occurences of linebreak with a ¤ sign (shift + 4).

Now, almost everyone know that the ¤ sign is almost never ever used for anything useful at all. As far as I know. :)
So a single linebreak/carrier return equals one ¤ sign, and a double linebreak (a paragraph) equals two ¤ signs.

And when you later on read the information from the database, you simply reverse the replacement. Replace the ¤ sign with a linebreak.
In VB.NET that would be VbCrLf.

Also. Converting all that text into html could pose a problem for you, becuase for some reason ASP.NET has some kind of built-in feature that thinks that certain kind of posted back HTML code is harmful, and thus will cause an exception error.

A way around that, I think, is to delve deeper into string replacement and figure out a way to use a combination of replacement characters for certain fonts and colors and formatting.
Like the one here on DaniWeb. :)

Wow! This is Really helpful.

I now remember, that sometime ago dring my ASP.Net class my teacher was trying to explain us the same concept. I wonder why didn't I notice it that time. May be I was sleeping in the class. As Usuall :P

Thanks a lot for this suggestion, I am going to use this idea to make my custom text editor for my bloging project. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.