473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2290
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="somethin g">

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">Co ntent 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******@hotma il.com> wrote in message
news:c8******** *************** ***@posting.goo gle.com...
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
5409
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 INSERT INTO JCTable ( CustomerName , CustomerNo ) VALUES ( 'Jon Combe' , 1 ) INSERT INTO JCTable ( CustomerName , CustomerNo ) VALUES ( 'Bill Gates' , 1 ) UPDATE JCTable SET CustomerNo = 2 WHERE CustomerName = 'Jon Combe'
1
3296
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 click on FormB, then back to FormA although the cursor is still flashing in the same textbox on FormA, when I tab out, the 'Leave' event for that TextBox does not fire. If I stay on FormA and Shift-Tab back into the textbox then the 'Enter' event...
10
2068
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 << " and &s = " << &s << "\n";
3
1851
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 Form which shows in each row a day of a month For the saturdays and sundays i wanted the row in a different color. I choose the conditioanal formating for an inputfield which was as wide as the whole form
2
2537
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 has been compiled with no error for days. The code was Me.CircuitQualifier.Requery
0
276
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 to be bound to the TextBox is called "s", and the TextBox itself is called "myTextBox", the binding is as follows (c#): myTextBox.Text = (s.StartsWith(Environment.NewLine) ? Environment.NewLine : "") + s;
2
2712
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 autofills with past entries for that textbox. My development workstation has the Google Toolbar installed; I'm not sure whether the autofill functionality is native to the browser or coming from the Google Toolbar. In either case, is there any way...
9
1295
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 situation where pressing the enter key on a textbox control is NOT captured by the KeyPress event? Now before you ask: -- The form does NOT have a default button selected.
0
1831
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, everything works okay. I can press <ENTER> when the cursor is inside the text box and the page is running, and no events fire (this is what I expect). But as soon as I drop a second text box on the page (ie: after th first one) then pressing...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.