MikeMCSD
asked on
MultiLine textbox -want to limit to 26 characters
I have a MultiLine textbox in a DataGrid that I want to limit to 26 characters max.
The MaxLength="26" property does not work for MulitLine textboxes.
I'm trying to use a Validator but it is not working:
<asp:TemplateColumn>
<ItemTemplate>
...........
<asp:TextBox ID="txtEng" TextMode="MultiLine" Rows="3" Width="245"
Runat="server"></asp:TextB ox>
<asp:RegularExpressionVali dator ID="regex"
ControlToValidate="txtEng"
ValidationExpression="^{1, 26}$"
Text="Engravings can only be a maxiumum of 26 characters"
Display="Dynamic"
ErrorMessage="Engravings can only be a maxiumum of 26 characters"
Runat="server" />
Any ideas on how I can limit the text to 26 characters max? thanks
The MaxLength="26" property does not work for MulitLine textboxes.
I'm trying to use a Validator but it is not working:
<asp:TemplateColumn>
<ItemTemplate>
...........
<asp:TextBox ID="txtEng" TextMode="MultiLine" Rows="3" Width="245"
Runat="server"></asp:TextB
<asp:RegularExpressionVali
ControlToValidate="txtEng"
ValidationExpression="^{1,
Text="Engravings can only be a maxiumum of 26 characters"
Display="Dynamic"
ErrorMessage="Engravings can only be a maxiumum of 26 characters"
Runat="server" />
Any ideas on how I can limit the text to 26 characters max? thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or you could use all in one line...like this:
onkeyup ="if(this.value.length>26) this.value=this.value.subs tring(0,26 )"
you can also use "onblur" event
onkeyup ="if(this.value.length>26)
you can also use "onblur" event
ASKER
thanks ak . . that works expect for when
the enter key is pressed. example:
Dear John
blahab blah
....
then it limits the number of characters to less than 18 or so.
this multiline texbox is a pain!
the enter key is pressed. example:
Dear John
blahab blah
....
then it limits the number of characters to less than 18 or so.
this multiline texbox is a pain!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@MikeMCSD have you tried my solution, I am pretty sure it will solve your problems even when a user presses the enter key.
ASKER
thanks, just tried it pt . . if I type in:
Dear John
Thanks
Love Mary
...which is 24 characters, it gives the message
"Exceeded 26 Characters!"
I think maybe it's including the enter key as a character . .
Dear John
Thanks
Love Mary
...which is 24 characters, it gives the message
"Exceeded 26 Characters!"
I think maybe it's including the enter key as a character . .
I was going to mention that it probably counts the enter key as one of the characters. This, however, is probably the closest you are going to get witht he Regular Expression Validator. The enter key has to count as something.
Instead of using a regular expression validator, use a custom validator that checks the length of the text.
Private Sub cvEng_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls. ServerVali dateEventA rgs) Handles cvEng.ServerValidate
if (txtEng.text.length > 26)
args.IsValid = false;
else
args.IsValid = true;
end if
End Sub
Private Sub cvEng_ServerValidate(ByVal
if (txtEng.text.length > 26)
args.IsValid = false;
else
args.IsValid = true;
end if
End Sub
ASKER
I'll have to come back to this later. thanks for your help
Runat="server" onkeyup="checkLength(this,