Saving text in asp.net

Thread Solved

Join Date: Oct 2007
Posts: 7
Reputation: palej is an unknown quantity at this point 
Solved Threads: 0
palej palej is offline Offline
Newbie Poster

Saving text in asp.net

 
0
  #1
Feb 11th, 2008
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

  1. 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());
  2. SqlDataSource1.InsertCommand = ins;
  3. SqlDataSource1.Insert();
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 7
Reputation: palej is an unknown quantity at this point 
Solved Threads: 0
palej palej is offline Offline
Newbie Poster

Re: Saving text in asp.net

 
0
  #2
Feb 12th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Saving text in asp.net

 
0
  #3
Feb 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 123
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Saving text in asp.net

 
0
  #4
Feb 12th, 2008
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.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Saving text in asp.net

 
0
  #5
Feb 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 123
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Saving text in asp.net

 
0
  #6
Feb 13th, 2008
Originally Posted by SheSaidImaPregy View Post
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?
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Saving text in asp.net

 
0
  #7
Feb 13th, 2008
  1. TextBox1.Text.Replace(Environment.NewLine, "<br/>")
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1081 | Replies: 6
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC