473,799 Members | 2,936 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 2288
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
5407
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
3295
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
2067
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
1849
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
2536
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
2711
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
1292
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
1828
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
10475
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
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
9068
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...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
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
5463
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3757
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.