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

Discussion in 'ASP .Net Web Controls' started by kalaiselvan, Aug 6, 2003.

  1. kalaiselvan

    kalaiselvan Guest

    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
     
    kalaiselvan, Aug 6, 2003
    #1
    1. Advertising

  2. 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]


    "kalaiselvan" <> wrote in message
    news:...
    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
     
    Ken Cox [Microsoft MVP], Aug 8, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWc=?=

    TextBox - MaxLength property

    =?Utf-8?B?bWc=?=, Apr 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,060
    coollzh
    Apr 11, 2004
  2. Craig G
    Replies:
    2
    Views:
    947
    Karl Seguin
    Feb 15, 2005
  3. bdb112
    Replies:
    45
    Views:
    1,371
    jazbees
    Apr 29, 2009
  4. kalaiselvan

    Closing Webforms - kalai

    kalaiselvan, Jul 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    90
    Alvin Bruney
    Jul 30, 2003
  5. mg

    TextBox - MaxLength property

    mg, Apr 11, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    402
    Scott Mitchell [MVP]
    Apr 16, 2004
Loading...

Share This Page