Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   maxlength on multiline textbox (http://www.velocityreviews.com/forums/t77471-maxlength-on-multiline-textbox.html)

hardcoded 05-05-2004 07:15 PM

maxlength on multiline textbox
 
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



William F. Robertson, Jr. 05-05-2004 07:17 PM

Re: maxlength on multiline textbox
 
No the max length doesn't work as the html tag rendered is a textarea tag,
which has no MaxLength property.

You will need to use a Validator control to ensure the length doesn't exceed
the MaxLength. You could use a RegExValidator or derive your own from
CustomValidator.

HTH,

bill


"hardcoded" <mtanner42@hotmail.com> wrote in message
news:%23qTtyUtMEHA.3668@TK2MSFTNGP11.phx.gbl...
> 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
>
>




hardcoded 05-05-2004 07:21 PM

Re: maxlength on multiline textbox
 
Just as I suspected. Thanks!

"William F. Robertson, Jr." <wfrobertson@kpmg.com> wrote in message
news:eFOrUWtMEHA.3664@TK2MSFTNGP10.phx.gbl...
> No the max length doesn't work as the html tag rendered is a textarea tag,
> which has no MaxLength property.
>
> You will need to use a Validator control to ensure the length doesn't

exceed
> the MaxLength. You could use a RegExValidator or derive your own from
> CustomValidator.
>
> HTH,
>
> bill
>
>
> "hardcoded" <mtanner42@hotmail.com> wrote in message
> news:%23qTtyUtMEHA.3668@TK2MSFTNGP11.phx.gbl...
> > 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
> >
> >

>
>




WJ 05-05-2004 08:23 PM

Re: maxlength on multiline textbox
 

"hardcoded" <mtanner42@hotmail.com> wrote in message
news:udF5XYtMEHA.2704@TK2MSFTNGP10.phx.gbl...
> Just as I suspected. Thanks!
>


Not much you can do on any web-based application. Price to pay for ! :)

John



i-Safire 05-25-2004 04:27 PM

Re: maxlength on multiline textbox
 
try the this

<HTML>
<HEAD>
<SCRIPT>
function fun_pTextarea_MaxLen(prm_oTextarea_Obj)
{ var var_sKey_Code, var_aKey_Special, var_bResult,
var_oTextarea_TxtRng;

var_oTextarea_TxtRng = prm_oTextarea_Obj.createTextRange();
var_aKey_Special = [8,17,18,27,33,34,35,36,37,38,39,40,45,46,114];
var_bResult = true;
var_sKey_Code = event.keyCode;
if (var_sKey_Code == 86)
{ if (event.ctrlKey) var_bResult =
fun_mTextarea_Paste(prm_oTextarea_Obj); }

if(prm_oTextarea_Obj.value.length >= prm_oTextarea_Obj.maxLen)
{ var_bResult = false;

if (var_oTextarea_TxtRng.queryCommandState('OverWrite ') &&
(prm_oTextarea_Obj.value.length == prm_oTextarea_Obj.maxLen))
{ var_bResult = true; }
else
{
for (i=0; i<var_aKey_Special.length; i++)
{ if (var_sKey_Code == var_aKey_Special[i]) {var_bResult = true;
break;} }
}
}

return var_bResult;
}

function fun_mTextarea_Paste(prm_oTextarea_Obj)
{ var var_sClipboard_Text;
var_sClipboard_Text = window.clipboardData.getData("Text");
prm_oTextarea_Obj.TxtRng =
document.selection.createRange().duplicate();

if (prm_oTextarea_Obj.TxtRng && prm_oTextarea_Obj.createTextRange)
{ prm_oTextarea_Obj.TxtRng.text =
prm_oTextarea_Obj.TxtRng.text.charAt(prm_oTextarea _Obj.TxtRng.text.length
- 1) == ' ' ? var_sClipboard_Text + ' ' : var_sClipboard_Text;
}
else
{ prm_oTextarea_Obj.TxtRng.text = var_sClipboard_Text;}

prm_oTextarea_Obj.value = prm_oTextarea_Obj.value.substring(0,
prm_oTextarea_Obj.maxLen);
return false;
}

</SCRIPT>
</HEAD>
<BODY>
<textarea maxLen=10 onkeydown="return
fun_pTextarea_MaxLen(this);"></textarea>
</BODY>
</HTML>

(phoenix398017)
"hardcoded" <mtanner42@hotmail.com> wrote in message news:<#qTtyUtMEHA.3668@TK2MSFTNGP11.phx.gbl>...
> 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


cnicol 09-26-2007 05:36 PM

Wow that's a really complex solution ... for a more lightweight solution perhaps this might fit some peoples needs:

javascript:

function textMaxLength(obj, maxLength, evt)
{
var charCode=(evt.which) ? evt.which : event.keyCode
var max = maxLength - 0;
var text = obj.value;
if(text.length > max)
{
var ignoreKeys = [8,46,37,38,39,40,35,36];
for(i=0;i<ignoreKeys.length;i++)
{
if(charCode==ignoreKeys[i])
{
return true;
}
}
return false;
}else
{
return true;
}
}

for the html part :

onKeyPress="return textMaxLength(this, '40', event);"


All times are GMT. The time now is 03:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.