Hey folks,

I have this problem, lets take this text from from 24ways.org just for example->

Elbow room

Paying attention to your typography is important, but it’s not just about making it look nice.

Careful use of the line-height property can make your text more readable, which helps everyone, but is particularly helpful for those with dyslexia, who use screen magnification or simply find it uncomfortable to read lots of text online.

When lines of text are too close together, it can cause the eye to skip down lines when reading, making it difficult to keep track of what you’re reading across.

So, a bit of room is good.

And Im making a site, which uses MSSQL and like above text if I save it to database (varchar(MAX)) it does loose all formattings and its just direct text without any Enters or formats. So how I dont loose formattings. Thnx.

I save the text this way and the MAIN text is that BlogBox.Text

string ins = string.Format("INSERT INTO blogs (topic, date, blog, author) VALUES ('{0}', '{1}', '{2}', '{3}')", TopicBox.Text, DateTime.Now.ToString("g"), BlogBox.Text, User.Identity.Name.ToString());
SqlDataSource1.InsertCommand = ins;        
SqlDataSource1.Insert();

Hmm, I've tryed something... I came now with this idea but i dont know how to do it.

How can I read Textbox.Text and parse it is there \r in between lines and so then I could add to the string \r (and of course multiline=true) ? or can it? :) Or is there something easier, simple property that i could set to True from properties :)

You can use regular expressions but that is complex for this. To use simple formating, just replace control characters with html, like:

Dim htmlText As String = BlogBox.Text
htmlText = htmlText.Replace(ControlChars.CrLf, "<br />")

Then just use htmlText in your insert command.

there are free asp.net html editors, you can include them in your project so when text is copied and paste to html editor, it will keep all the formatting tags.However, to enter html, i guess you will have to set validaterequest attribute of the page to false in order not for asp.net to generate request validation error.

A simple find a replace command is what makes it work.

Just search for the environment.newline and replace it with <br /> in the output.

Keep in mind you cannot insert <br /> into the database, therefore ONLY format when it is retrieved.

A simple find a replace command is what makes it work.

Just search for the environment.newline and replace it with <br /> in the output.

Keep in mind you cannot insert <br /> into the database, therefore ONLY format when it is retrieved.

can you give us a complete example?

TextBox1.Text.Replace(Environment.NewLine, "<br/>")
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.