Preserving white space in iframe control using style sheet="white-space:pre"

I am suing iframe control in the edit mode.

I need to preserve white space in the control.

e.g. if I put following data in the control and then save in the database,

SSDB.CLMP1SO              735837              735837               0           0
SSDB.CNCP2SO              735837              735837               0           0
SSDB.CYMP3SO              735837              735837               0           0
SSDB.CYMP4SO              735837              735837               0           0
SSDB.RCPP1SO              735837              735837               0           0

and reload in the iframe control, the extra white space between the word is removed.

I tried style="white-space:pre" but that does not seem to work.

I do not want to use <pre></pre>, as I am doing some active formatting in the control.

As suggested in the article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie60/html/cssenhancements.asp

Even after turning the <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> standard compliant mode on, iframe element does not seem to support white-space:pre style.

Please suggest.

Thanks,


Paresh
0
Paresh
12/22/2006 5:09:20 PM
📁 asp.net.client-side
📃 24353 articles.
⭐ 1 followers.

💬 11 Replies
👁️‍🗨️ 966 Views

for an interesting read on PRE, i'd recommend this article: http://cheeaun.phoenity.com/weblog/2005/06/whitespace-and-generated-content.html

 

 


Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
12/22/2006 6:33:07 PM

Very good read indeed - thanks. Since the trials there are not applicable to internet explorer at all, I will not be able to use them.

I know that preserving white space in the iframe control is possible in internet explorer.

I am using innovaEditor which supports that - I don't know how they achieve it. (It does not seem to be style sheet)

http://www.innovastudio.com/

I need to be able to do that in my own application.

Any suggestions?

Thx,


Paresh
0
Paresh
12/22/2006 7:00:26 PM

if the whitespace is preserved without pre or a css style, then i would suspect it is being entered as nonbreaking space entities

i.e.

&nbsp;

or

chr(160)

just a guess though...


Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
12/22/2006 8:16:06 PM

Actually my problem is - I want to preserve it.

It is not being preserved. (I know they are stored OK in the database as if I reload it in a normal textarea they are shown)

However, if I reload it in an iframe - they are lost.


Paresh
0
Paresh
12/22/2006 8:24:10 PM

correct. when you dont use a pre tag and you havent applied some form of css to prevent it, the browser will collapse repeating whitespace characters into a single whitespace character.  this is how the browser renders spaces.

to not use css and to not use a pre tag, you would need to replace the whitespace chars with "&nbsp;" for display purposes only.

i.e. when assigning the db value to a label you could try something like:

Label1.Text = myDbValue.Replace(" ", "&nbsp;")

But when assigning that same value to a multiline textbox, you would not alter it

TextBox1.Text = myDbValue

This same technique is also used for CRLF's entered in a multiline textbox.

Label1.Text = myDbValue.Replace(Environment.Newline, "<br />")
 
Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
12/23/2006 6:22:31 PM

Mike,

Thanks for this suggestion, I will try replaced space with &nbsp; as you suggested.

Here is how I defined my iframe control with CSS to instruct it to preserve white space. But that does not seem to work.

<iframe id="xyz" style="white-space:pre">

</iframe>

I was hoping that would work.

Thx,

Paresh.


Paresh
0
Paresh
12/23/2006 9:40:00 PM

i do not believe that the css style of an iframe actually affects the content of the document that is contained inside the iframe. I suspect this is why your style did not have the desired affect. 

Perhaps you can do the &nbsp; replacement or perhaps you can get the white-space:pre into the content you reference in the iframe.


Mike Banavige
~~~~~~~~~~~~
Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
12/23/2006 10:20:38 PM

Mike,

 Thanks a bunch.

Using &nbsp; solved the issue in the applications which I designed in house.

However, I need to do the same thing in one of our third party applications too and there if I replace space with "&nbsp;" it shows up as it is with "&" replaced with some other character.

 SSDB.CNCP2SO ;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;�nbsp;735837�nbsp;

So, I tried replacing it with "&amp;nbsp" - but still no use, I am getting this.

SSDB.RCPP2SO&;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;�amp;nbsp;735837�amp

Any idea what might be happening here?

I am using javascript to replace "space" with "&nbsp;" - like this.

document.frmNotes.txaWorkNote.value = document.frmNotes.txaWorkNote.value.replace(/ /gi,"&nbsp;");

I guess their might be some settings in the control of the third party application which does that - but not able to determine what.

Any suggestions?

Thx,

Paresh.

 

 


Paresh
0
Paresh
12/26/2006 12:17:20 AM

I think I know the reason for the above issue.

1. If I replace space using vbscript directly on the database output like replace(fieldname, " ", "&nbsp;") - everything works fine.

2. However if I use javascript to do the same using document.frmNotes.txaWorkNote.value.replace(/ /gi,"&nbsp;"), it results in above mess.

In the application where I need to use javascript, I need to fixe this.

Can't seem to find a logical reason for the difference though.

Any suggestions?

 Thx,

Paresh.


Paresh
0
Paresh
12/26/2006 9:39:05 PM

I guess the much cleaner solution can be:  to specify <style> body {white-space:pre} </style> for the document.

And then to make the browser compliant by specifying:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

 Unfortunately that does not change iframe content behavior.

If iframe content is defined dynamically - is there any way to specify !DOCTYPE for the iframe element in IE?

Thanks,

Paresh.


Paresh
0
Paresh
12/28/2006 9:01:05 PM

Mike,

 

Thanks - that was useful. Looks like I need to replace space with "&nbsp;" to achieve the behavior I am looking for.

However I have an issue:

Suppose the data is "xx                  yy                zz"

At some points in my application I can do it while loading my data back from the database on the server side.

(First it gets loaded into a textarea and then to an iframe down the line)

 e.g. replace(columnname, " ", "&nbsp;") - which works fine - no issues.

I see "xx               yy             zz" in the textarea and same thing correctly in the iframe at the later stage.

However at other places I need to use Javascript as data loaded to iframe comes from the textarea without any trip to the database.

However, if I use javascript to replace white space: like myText.replace(/ /gi, "&nbsp;")

The textarea gets populated with "xx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zz"

I guess "&nbsp;" is taken as string.

How do I achieve same behavor as server side replacement of space with "&nbsp;" using javascript?

Any ideas?

Thanks,

Paresh.


Paresh
0
Paresh
12/29/2006 4:25:25 PM
Reply: