By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,665 Members | 1,900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,665 IT Pros & Developers. It's quick & easy.

How to add a Validator for a TEXTBOX with TextMode = multiLine

P: n/a
RSB
Hi Guys..
its me again.. ;o))

now i have a TextBox with properties Textmode = singleline and MaxLength =
100. So this works fine and i cannot enter more then 100 Chars. But as soon
as i change the TextMode to MultiLIne the MaxLength gets ignore as it is
painted as TEXTAREA. so how do i add a validator control to make sure that
user is not entering more than 100 Characters..

Thank you for the help in advance.

RSB.

Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
you cant use MaxLength with a multiline.You'll have to use a CustomValidator
I believe and manually check the length of the string.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"RSB" <rs*****@hotmail.com> wrote in message
news:T2****************@news.cpqcorp.net...
Hi Guys..
its me again.. ;o))

now i have a TextBox with properties Textmode = singleline and MaxLength = 100. So this works fine and i cannot enter more then 100 Chars. But as soon as i change the TextMode to MultiLIne the MaxLength gets ignore as it is
painted as TEXTAREA. so how do i add a validator control to make sure that
user is not entering more than 100 Characters..

Thank you for the help in advance.

RSB.

Nov 18 '05 #2

P: n/a
Hi

You have to use javascript & you should check the length on the server also

Basic example:
<textarea onkeydown="if(this.value.length >= 100){alert('Only blah'); return
false;}">

More info
http://msdn.microsoft.com/library/de...ence_entry.asp

--
Best Regards
Vidar Petursson
==============================
Microsoft Scripting MVP
http://www.microsoft.com/technet/scriptcenter
==============================
"RSB" <rs*****@hotmail.com> wrote in message
news:T2****************@news.cpqcorp.net...
Hi Guys..
its me again.. ;o))

now i have a TextBox with properties Textmode = singleline and MaxLength
=
100. So this works fine and i cannot enter more then 100 Chars. But as
soon
as i change the TextMode to MultiLIne the MaxLength gets ignore as it is
painted as TEXTAREA. so how do i add a validator control to make sure that
user is not entering more than 100 Characters..

Thank you for the help in advance.

RSB.

Nov 18 '05 #3

P: n/a
try this the following, this will prevent user from entering more
characters than maxLen specified; it works in all the situations,
including:
1) copy and paste;
2) insert key on;

<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>
(ref:phoenix398017)

"RSB" <rs*****@hotmail.com> wrote in message news:<T2****************@news.cpqcorp.net>...
Hi Guys..
its me again.. ;o))

now i have a TextBox with properties Textmode = singleline and MaxLength =
100. So this works fine and i cannot enter more then 100 Chars. But as soon
as i change the TextMode to MultiLIne the MaxLength gets ignore as it is
painted as TEXTAREA. so how do i add a validator control to make sure that
user is not entering more than 100 Characters..

Thank you for the help in advance.

RSB.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.