Textbox maxlength setting - for multline property set to true - kalai

K

kalaiselvan

Hi,
I have a Text box and set its multiline property to "TRUE". How can i set
it maxlength property. I need to set its maxlength property to 255. Can
anyone help me out.
Thx,
kalai
 
K

Ken Cox [Microsoft MVP]

The textarea control (used for multiline textbox) doesn't support a maxlength.
However, you can insert a little Javascript on the client to trim the excess
text when the textarea loses the focus. Here's a little example:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim sb As New System.Text.StringBuilder
sb.Append("<script language='javascript'>function ")
sb.Append("checklen(){var str=document.forms[0].TextBox1.value;")
sb.Append("document.forms[0].TextBox1.value=")
sb.Append("str.substring(0,255);}</script>")
Page.RegisterClientScriptBlock("chker", sb.ToString)
TextBox1.Attributes.Add("onblur", "checklen();")
End Sub

<form id="Form1" method="post" runat="server">
<p>
<asp:textbox id="TextBox1" runat="server" textmode="MultiLine"
maxlength="255" width="390px"
height="176px"></asp:textbox></p>
<p>
<asp:button id="Button1" runat="server" text="Button"></asp:button></p>
</form>

Does this help?

Ken
MVP [ASP.NET]


Hi,
I have a Text box and set its multiline property to "TRUE". How can i set
it maxlength property. I need to set its maxlength property to 255. Can
anyone help me out.
Thx,
kalai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top