473,569 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't MaxLength work with multiline TextBoxes?

I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />

The ideas is that users get 100 characters to specify their subject. In
fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since it's
mentioned in the documentation, but it certainly is a design flaw in my
opnion.

Now I have to set up a validator to make sure the string isn't too
long, and users will have no idea they have typed too much until they
hit Submit and get an error message. I suppose I could say "max of 100
characters" next to the textbox, but this will clutter up the page,
and, assuming users even know what a "character" is, what are they
supposed to do, count?

I don't know if this is a Microsoft thing or just a limitation with
html, but I hope someone fixes it soon.

-Dan

Jan 1 '06 #1
10 3651
Hello danthman,
I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />
The ideas is that users get 100 characters to specify their subject.
In fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since
it's mentioned in the documentation, but it certainly is a design flaw
in my opnion.


Well, tell that to the HTML spec designers ;-)

All ASP.NET web controls are ultimately rendered as HTML elements. Unfortunately,
a TextArea has no MaxLength property...

Cheers,
--
Joerg Jooss
ne********@joer gjooss.de
Jan 1 '06 #2
The ASP.NET TextBox of one line renders as an HTML <INPUT type="Text"... >
element, whereas a TextBox with multiple lines renders as an HTML <TextArea>
element, which has no MaxLength property per the HTML specification. This
isn't a specification that Microsoft put together. This is what we got from
the lovely standards commmittee.

A couple of workarounds:
http://www.dynamicdrive.com/dynamici.../maxlength.htm

http://www.siteexperts.com/ie5/htc/ts08/page1.asp

Another workaround is to use a validator with its problems as you are
already apparently aware.

-Jeff

"danthman" <da******@cox.n et> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />

The ideas is that users get 100 characters to specify their subject. In
fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since it's
mentioned in the documentation, but it certainly is a design flaw in my
opnion.

Now I have to set up a validator to make sure the string isn't too
long, and users will have no idea they have typed too much until they
hit Submit and get an error message. I suppose I could say "max of 100
characters" next to the textbox, but this will clutter up the page,
and, assuming users even know what a "character" is, what are they
supposed to do, count?

I don't know if this is a Microsoft thing or just a limitation with
html, but I hope someone fixes it soon.

-Dan

Jan 1 '06 #3
MS could have, however, emitted the JavaScript necessary to restrict the
number of characters. You can do that, but it requires JavaScript to count
the number of characters with each key stroke.

"Jeff" <A@B.COM> wrote in message
news:e6******** ******@tk2msftn gp13.phx.gbl...
The ASP.NET TextBox of one line renders as an HTML <INPUT type="Text"... >
element, whereas a TextBox with multiple lines renders as an HTML
<TextArea> element, which has no MaxLength property per the HTML
specification. This isn't a specification that Microsoft put together.
This is what we got from the lovely standards commmittee.

A couple of workarounds:
http://www.dynamicdrive.com/dynamici.../maxlength.htm

http://www.siteexperts.com/ie5/htc/ts08/page1.asp

Another workaround is to use a validator with its problems as you are
already apparently aware.

-Jeff

"danthman" <da******@cox.n et> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />

The ideas is that users get 100 characters to specify their subject. In
fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since it's
mentioned in the documentation, but it certainly is a design flaw in my
opnion.

Now I have to set up a validator to make sure the string isn't too
long, and users will have no idea they have typed too much until they
hit Submit and get an error message. I suppose I could say "max of 100
characters" next to the textbox, but this will clutter up the page,
and, assuming users even know what a "character" is, what are they
supposed to do, count?

I don't know if this is a Microsoft thing or just a limitation with
html, but I hope someone fixes it soon.

-Dan


Jan 2 '06 #4
As everyone else mentioned, it is due to the limitations of HTML. However, I
believe the reason for this has something to do with carriage returns, line
breaks, and other whitespace characters used between lines. Different
browsers and operating systems might use different combinations of these
characters to represent a new line, and depending on whether they use a
single character or the combination of Chr(13) and Chr(10) like Microsoft
does, the same text may be a different number of characters. Because I have
read the specs cover to cover, I don't know for sure, but this is my guess.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"danthman" <da******@cox.n et> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />

The ideas is that users get 100 characters to specify their subject. In
fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since it's
mentioned in the documentation, but it certainly is a design flaw in my
opnion.

Now I have to set up a validator to make sure the string isn't too
long, and users will have no idea they have typed too much until they
hit Submit and get an error message. I suppose I could say "max of 100
characters" next to the textbox, but this will clutter up the page,
and, assuming users even know what a "character" is, what are they
supposed to do, count?

I don't know if this is a Microsoft thing or just a limitation with
html, but I hope someone fixes it soon.

-Dan

Jan 2 '06 #5
danthman wrote:
I have a TextBox set up as follows:

<asp:TextBox
ID="SubjectText Box"
TextMode="Multi Line"
MaxLength="100"
Columns="50"
Rows="2"
Wrap="true"
runat="server" />

The ideas is that users get 100 characters to specify their subject. In
fact, the content of this TextBox will get inserted into a database
field whose data type is VARCHAR(100).

Unfortunately, the MaxLength property gets disabled/ignored when the
TextMode is set to "multiline. " This isn't officially a bug, since it's
mentioned in the documentation, but it certainly is a design flaw in my
opnion.

Now I have to set up a validator to make sure the string isn't too
long, and users will have no idea they have typed too much until they
hit Submit and get an error message. I suppose I could say "max of 100
characters" next to the textbox, but this will clutter up the page,
and, assuming users even know what a "character" is, what are they
supposed to do, count?


You should always setup validators for limitations. The MaxLength you
set with TextBox affects only the UI - users can still send you a
1GB-long text without being cut (they dont have to use a browser).

Maybe ASP.NET should add automatic validators for that in next version?

Jan 2 '06 #6
Pardon my naivete, but how do you send text without using the
interface? And, if you did do that, what good would it do to write a
validator that checks what's been typed into the textbox? Also, what
would happen if someone sent something bigger than the max the database
field is set up to hold (e.g., VARCHAR(100))? Wouldn't it just generate
an error and reject the attempt?

Thanks,

-Dan

Jan 2 '06 #7
The UI is simply an easy way to allow the user to input information. The
information sent to the browser is simply a text document that is then
processed. In the simple case, a user might setup a bunch of hidden fields
that are named the same as your input fields and set the values. Then they
can submit that form to your page. There is no difference between a hidden
field and a UI field from the perspective of the server (they are all just
name/value pairs). A more complicated plan might be to craft the post data
(sans a web page) that the server will process, which as I mentioned is
really only a text document.

The point being that the client is very susceptible to spoofing and that no
assumptions should be made in case some bad hacker decides your sites is
worth spoofing.

"danthman" <da******@cox.n et> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Pardon my naivete, but how do you send text without using the
interface? And, if you did do that, what good would it do to write a
validator that checks what's been typed into the textbox? Also, what
would happen if someone sent something bigger than the max the database
field is set up to hold (e.g., VARCHAR(100))? Wouldn't it just generate
an error and reject the attempt?

Thanks,

-Dan

Jan 2 '06 #8
danthman wrote:
Pardon my naivete, but how do you send text without using the
interface?
Just HTTP. The browser is the *user*'s tool to connect to your server.
You can't do real validation based on his own tool.
And, if you did do that, what good would it do to write a
validator that checks what's been typed into the textbox?
It should be provided automatically. Since a control in ASP.NET is like
a GUI control, its behavior should also be consistent.
Also, what
would happen if someone sent something bigger than the max the database
field is set up to hold (e.g., VARCHAR(100))? Wouldn't it just generate
an error and reject the attempt?


It could cause buffer overflow or other weird error before your DB
validates it against the field length. Also, with MySQL's MyISAM DB,
it's just truncated without any error thrown.

Database is mainly for storage, and you'd have a lot of trouble if you
want to rely on it for other tasks. Think of a simple example: you have
a table with field "name" and field "password", both are VARCHAR(20),
and some user gives a password of 21 chars. Here the problem comes: DB
rejects the INSERT, but how do you know which field is wrong? The
length checking is not a named constraint, and every DBs report error
in different ways!

Jan 2 '06 #9
Thanks, guys.

Okay, so tell me if I have this right...

The validation is done by the server. Users can send whatever they want
to the server by writing their own html files and loading them in their
browsers, but if I write validators to protect against all bad data,
they can't hurt me (well, not easily anyway).

I'm a littler hazier on the database issue though. If I send too much
data to the database, and it causes "buffer overflow or some other
wierd error," would this crash my server? Or would the user's attempt
just simply not work and cause them to see a cryptic error message?

I will definitely do my best to validate against all possible bad data,
but if I miss something, I hope it's at least very difficult to crash
the server. If it were just a matter of someone getting an unhandled
exception or something, I could live with that, especially if they did
something malicious to generate the exception :)

Anyway, thanks for the warning. I'll work on some stricter validators.

-Dan

Jan 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4021
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The problem is that only the modified data from the SingleLine TextBoxes are returned. The original data are returned for the MultiLine TextBoxes. Also,...
1
466
by: mg | last post by:
I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be typed into this TextBox?
4
8155
by: hardcoded | last post by:
I have a textbox with TextMode set to MultiLine. I also have the MaxLength set to 255. This maxlength value seems to get ignored as the user can enter unlimited characters. Does the multiline textbox not support maxlength? How can I make the work? TIA
3
5042
by: RSB | last post by:
Hi Everyone, I have this TextBox with the TextMode="MultiLine". so now it does not validate the text in the TextBox for the MaxLength SO i have decided to execute a CustomValidator for this Textbox and run a CLientSideFunction. now i was making this clientsidefunction generic so that i can validate all the other textboxes also. Now to do...
2
1425
by: Craig G | last post by:
how do you do it? i understand the maxlength property has no effect but is there a way around it?
6
8039
Coldfire
by: Coldfire | last post by:
I am having problems with Maxlength of Multiline "Textbox". I have browsed alot to find the solution. Tons of javascripts have been found but they all deal with <asp:textarea >............. and not <asp:TextBox >............. and some of javascripts are 1-------------------------------------------- <script language="JavaScript">
3
3123
by: gomzi | last post by:
hi, I am trying to set the maxlength property of a multiline textbox without much success. Could anyone tell me as to how it could be done ? thanks, gomzi.
3
5539
by: whitey | last post by:
this code is producing the message BUT it is entering the data. What should i do? <?php if (!$_POST) { //haven't seen the form, so show it $display_block = " <form method=\"post\" action=\"".$_SERVER."\"> <p><strong>First/Last Names:</strong><br/> <input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\">
15
3052
by: colyn7 | last post by:
I really can't see what's wrong in my code... the submit() onChange doesn't work.. I've tried.. <select name="ddlTestCenter" id="ddlTestCenter" style="width:180px" onChange="this.form.submit();"> it doesn't work... <input type="hidden" name="hiddenopt" value="secret"> <select name="list" onChange="document.forms.submit();">
0
7703
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...
0
7618
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...
0
8138
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...
0
7983
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...
0
6287
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...
0
5223
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...
0
3657
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...
1
2117
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
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.