By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Weird TextBox behaviour

P: n/a
The TextBoxes in ASP have a weird behaviour when it comes to handling
carriage returns. You can try this :

Create a Webform. On it, place a textbox, set it's TextMode property
to MultiLine.
Place a button. Double-click on the button and in it's event handler,
just type :

TextBox1.Text = TextBox1.Text ;

(if you're doing this in VB, just omit the ";").

Show that page in your favorite browser, or even inside the IDE. Type
two carriage returns (nothing fancy, plain old "Return" key), then any
text.

Now click on the button : the first CR disappears. Click again : the
next CR disappears. The rule is : if there is a CR at the top of the
text, it will be deleted.

Took me a while to figure, bacause at first I thought it was my
DataAdapter messing with the xml. I've searched the groups to no
avail. I'm doing this with VS 2003 and 2005 is not an option (yet).

Has anyone found a workaround to this? I'm stumped. Thanks in advance.

Michel
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I believe your problem may result from setting the textbox's text property
to its own text property, combined with a bit of weirdness on the part of
the .Net platform.

In HTML, there are 2 types of "TextBoxes." The single-line text box renders
(approximately) the following HTML:

<input type="text" name="something" id="something" value="something">

Note that the "value" attribute is an attribute. A "multi-line textbox" is a
different HTML element:

<textarea name="something" id="something" rows="3" columns="60">Content goes
here.
Content may contain carriage returns,
as demonstrated here. Note that content is unformatted text.</textarea>

Now, as you should know, HTML considers all "white space" characters,
including line feeds, tabs, spaces, etc. to be single spaces when rendered.
HTML allows elements to span more than one line. So, what happens when you
do this with a textarea?

<textarea name="something" id="something" rows="3" columns="60">
</textarea>

It would seem that there is nothing in the textarea. However, there IS
something: a carriage return. HTML rules allow you to break tags across
lines, and the above example is a perfectly legitimate textarea. But, due to
the pre-formatted nature of the text inside, it does contain a line feed.
Many developers often make the mistake of designing a textarea in this way,
and are puzzled by the extra line feed in their result. Now, I'm going to
theorize a bit here, and am guessing that the developers of ASP.Net saw this
trend, and decided to "correct" it, by eliminating any line feed at the
beginning of a textarea. My guess would be that if you don't reassign the
value, the PostBack will retain the value as original, as long as you've
enabled ViewState for it. Have you tried this?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"fd123456" <fd******@hotmail.com> wrote in message
news:c8**************************@posting.google.c om...
The TextBoxes in ASP have a weird behaviour when it comes to handling
carriage returns. You can try this :

Create a Webform. On it, place a textbox, set it's TextMode property
to MultiLine.
Place a button. Double-click on the button and in it's event handler,
just type :

TextBox1.Text = TextBox1.Text ;

(if you're doing this in VB, just omit the ";").

Show that page in your favorite browser, or even inside the IDE. Type
two carriage returns (nothing fancy, plain old "Return" key), then any
text.

Now click on the button : the first CR disappears. Click again : the
next CR disappears. The rule is : if there is a CR at the top of the
text, it will be deleted.

Took me a while to figure, bacause at first I thought it was my
DataAdapter messing with the xml. I've searched the groups to no
avail. I'm doing this with VS 2003 and 2005 is not an option (yet).

Has anyone found a workaround to this? I'm stumped. Thanks in advance.

Michel

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.