Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Line breaks in Textarea's
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 01 March 2002 :  11:25:00  Show Profile
If I put some text into a <textarea> and then save it into a database when I display it in another texarea it is formatted correctly, ie line breaks, new paras etc. But when I display the same text on the page without putting it in a <Textarea> the formatting is lost.

Do I have to identify vbCrlf's in the text and change them to <BR>'s etc? if so how?

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 01 March 2002 :  11:52:02  Show Profile  Visit Kat's Homepage
When you write the value from a textarea into the database, encode it first:

strTextAreaText = Server.HTMLEncode(Request.Form("strTextAreaText"))



KatsKorner

For Installation help: http://www.aslickpage.com/snitz_help.html
For Snitz Mods: http://ls3k.com/snitz/

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 01 March 2002 :  12:21:14  Show Profile  Send ruirib a Yahoo! Message
I would do it the other way around. Your database is meant to store text. So I would always store text without any change whatsoever. Data would always remain unchanged.

Data display (in this case text display) is another matter. If you need to convert your text to some format to display it properly, then you take care of that when displaying it. And if your display format needs to change by any reason, or if you need to display it in different media, or whatever, than supply a conversion function suitable to each situation requirements.

From a software engineering point of view this is the best option. You may consider that always performing the same conversion to display data wastes CPU cycles and to avoid data store info in a display suitable format. OK. But if, somewhere along the way, you need another format it may be more difficult to do it.
I understand that my point of view is disputable. Hey, it's just the way I see it. Storage is storage, display is display.

So I would store the text without changes and convert it for display, whenever needed...

Sorry to disagree with you on this one, Kat .



-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Nathan
Help Moderator

USA
7664 Posts

Posted - 01 March 2002 :  22:05:59  Show Profile  Visit Nathan's Homepage
If you need to go back and edit it, then you will want to store it as text. However, if you will be putting HTML like Tables or somthing in the textarea then you will want to store it in the database as HTML to avoide complications (As I have learned working with the Rich Text Editor mod.)

 Nathan Bales - Romans 15:13
---------------------------------

Snitz Exchange | Mod Resource
Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 04 March 2002 :  04:23:48  Show Profile
I have gotta say I like Kats solution as its really simple and gets me over the problem immediately - thanks Kat - however can anyone give me an example of the sort of thing ruirib mentioned. Assume text stored in DB was input via a <textarea> and is unmodified, how do I now display as text on a page of HTML with breaks and para's intact? Thanks

Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 04 March 2002 :  04:23:48  Show Profile  Visit Kat's Homepage
quote:



Sorry to disagree with you on this one, Kat .




Not a problem. Each to their own .

KatsKorner

For Installation help: http://www.aslickpage.com/snitz_help.html
For Snitz Mods: http://ls3k.com/snitz/

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 04 March 2002 :  06:05:17  Show Profile  Send ruirib a Yahoo! Message
quote:

I have gotta say I like Kats solution as its really simple and gets me over the problem immediately - thanks Kat - however can anyone give me an example of the sort of thing ruirib mentioned. Assume text stored in DB was input via a <textarea> and is unmodified, how do I now display as text on a page of HTML with breaks and para's intact? Thanks



I think it woulb be as simples as using Server.HTMLEncode() on the value read from the database and displaying the result.
From a practical point of view it is very similar to what Kat suggested, except for having to be done every single time you need to display the info. The difference would lie on the fact that for different "display needs" (if you had them), you could simply use another converter, instead of Server.HTMLEncode(). Also, if for any reason, you needed to access the text without HTML, you'd read it directly from the DB, no conversion needed. Obviously, if you had the text with HTML and needed to use it without HTML, you could always convert it when you needed it.

If what you always do is display it as HTML Kat's solution is a more economical one in terms of CPU use - no need to perform the conversion every time. Convert it once and that's it.


-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 04 March 2002 :  07:48:20  Show Profile  Visit Kat's Homepage
I must admit that I have used Server.HTMLEncode()lots of times with great effect to do exactly what you need Terry. It is a quick solution.

KatsKorner

For Installation help: http://www.aslickpage.com/snitz_help.html
For Snitz Mods: http://ls3k.com/snitz/

Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 04 March 2002 :  09:34:55  Show Profile
Thanks Kat

Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 04 March 2002 :  12:42:52  Show Profile
Kat, Is there any reason why your solution would not work, like something has to be enabled on the server?
Using Server.HTMLEncode(Request.Form("MyField")) seems to do nothing for me, it displays just the same as it did before. If I use Server.HtmlEncode in the way ruirib mentions it also does nothing unless the database field contains some HTML like <P> (huge fluke) in which case the HTML is displayed in line with the text. Dont let that muddy the water though, iam not trying to display HTML or avoid it, just to have text displayed as it is in a textarea where it still retains the formatting created by using the reurn key.I get the feeling I am doing something really basic wrong.

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 04 March 2002 :  12:54:34  Show Profile  Send ruirib a Yahoo! Message
Terry, it seems sometimes we do lose track of the beggining of the topic.

I'm not sure whether Server.HTMLEncode changes VbCrlf intro <br>.

You can use the Replace function for that:


Replace(YourStringVariable,VbCrLf,"<br>")
Response.Write YourStringVariable


This will write your string with VbCrLf's replaced by <br>.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 05 March 2002 :  04:25:25  Show Profile  Visit Kat's Homepage
Terry,

Take a look at this example of how I have used textareas. I first encode the value as I described above with Server.HTMLEncode(). I then use the following to display the items:

<%Dim linefeed = Chr(10)
linefeed = Chr(10)

if strSomeTextArea <> "" then
%>
<tr>
<td colspan="<%=strColSpan%>" align="left" valign="top"> </td>
</tr>

<tr>
<td colspan="<%=strColSpan%>" class="boldlinks" valign="top" align="left">Abstract:</td>
</tr>
<tr>
<td style="font-size:1px;" colspan="<%=strColSpan%>" align="left" valign="top"> </td>
</tr>
<td colspan="<%=strColSpan%>" class="smallnonboldlinks" valign="top" align="left">
<%
for i = 0 to ubound(Split(strSomeTextArea ,linefeed))
Response.Write(Split(server.htmlencode(strSomeTextArea ),linefeed)(i)) & "<br>"
next

%>
</td>
</tr>
<%
end if
%>


I am sorry I can't detail any more right now but I hope you can try and use the basis of this.

Kat.

KatsKorner

For Installation help: http://www.aslickpage.com/snitz_help.html
For Snitz Mods: http://ls3k.com/snitz/



Edited by - kat on 05 March 2002 04:28:18
Go to Top of Page

TerryG
Junior Member

United Kingdom
179 Posts

Posted - 05 March 2002 :  09:08:05  Show Profile
Dont be sorry, the example is perfect, Thanks for taking the trouble to reply in detail.

Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 05 March 2002 :  09:13:56  Show Profile  Visit Kat's Homepage
No trouble at all. I just had to dig around a little for the example that's all.... I knew I had one somewhere.....

I hope it works for you .

KatsKorner

For Installation help: http://www.aslickpage.com/snitz_help.html
For Snitz Mods: http://ls3k.com/snitz/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.4 seconds. Powered By: Snitz Forums 2000 Version 3.4.07