Author |
Topic |
|
TerryG
Junior Member
United Kingdom
179 Posts |
Posted - 01 March 2002 : 11:25:00
|
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 |
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 01 March 2002 : 12:21:14
|
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 |
|
|
Nathan
Help Moderator
USA
7664 Posts |
Posted - 01 March 2002 : 22:05:59
|
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 |
|
|
TerryG
Junior Member
United Kingdom
179 Posts |
Posted - 04 March 2002 : 04:23:48
|
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
|
|
|
Kat
Advanced Member
United Kingdom
3065 Posts |
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 04 March 2002 : 06:05:17
|
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 |
|
|
Kat
Advanced Member
United Kingdom
3065 Posts |
|
TerryG
Junior Member
United Kingdom
179 Posts |
Posted - 04 March 2002 : 09:34:55
|
Thanks Kat
|
|
|
TerryG
Junior Member
United Kingdom
179 Posts |
Posted - 04 March 2002 : 12:42:52
|
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.
|
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 04 March 2002 : 12:54:34
|
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 |
|
|
Kat
Advanced Member
United Kingdom
3065 Posts |
Posted - 05 March 2002 : 04:25:25
|
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 |
|
|
TerryG
Junior Member
United Kingdom
179 Posts |
Posted - 05 March 2002 : 09:08:05
|
Dont be sorry, the example is perfect, Thanks for taking the trouble to reply in detail.
|
|
|
Kat
Advanced Member
United Kingdom
3065 Posts |
|
|
Topic |
|