473,416 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Weird TextBox behaviour

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
1 2247
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jon Combe | last post by:
I have created the following test SQL code to illustrate a real problem I have with some SQL code. CREATE TABLE JCTable ( CustomerName varchar(50) ) ALTER TABLE JCTable ADD CustomerNo int...
1
by: Chris Mayers | last post by:
Hi, I have an application that has (for the sake of argument) 2 (MDI) windows open. If I click into a textbox on FormA then the 'Enter' event for that TextBox fires, great! However, if I then...
10
by: Chris Mantoulidis | last post by:
I see some really weird output from this program (compiled with GCC 3.3.2 under Linux). #include <iostream> using namespace std; int main() { char *s; s = "test1"; cout << "s = " << s << "...
3
by: Benjamin Z. Gregorian | last post by:
Hi there I have a problem with a database I wrote. On my access 2002 it is running without probs but on the comp of my collegue A2003 there is this weird behaviour. The form is a continuous...
2
by: Kathy Houtami | last post by:
Hi there I've been encountered with weird compile error using Access 97. The error message is "Member or data member is not found" and it highlighted a line of code that has not be changed and...
0
by: fd123456 | last post by:
Hi Kevin, You were indeed right. Unfortunately, the ViewState property doesn't change that behaviour. In case it can help someone else, here's the trick I ended up doing. Supposing the variable...
2
by: Andre Ranieri | last post by:
I'm retouching our corporate web site that, among other things, allows customers to log in and pay their invoices online. I noticed that on the checkout page, the credit card number textbox...
9
by: ZorpiedoMan | last post by:
This is so weird, and I cannot even isolate the cause enough to give any clues as to how to reproduce the error, so this is probably a real shot in the dark... BUT, has anyone ever run into a...
0
by: Tom Edelbrok | last post by:
I'm using VS 2005 to develop an intranet asp.net web application and I get a weird situation. If I start out with any ASPX page that contains an ImageButton control followed by a TextBox control,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.