Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to set Maximum Length In Multiline Mode of TextBox

how to set Maximum Length In Multiline Mode of TextBox

Scheduled Pinned Locked Moved ASP.NET
sysadminhelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jintal Patel
    wrote on last edited by
    #1

    i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.

    function textboxMultilineMaxNumber(txt,maxLen){
    try{
    if(txt.value.length > (maxLen-1))return false;
    }catch(e){
    }
    }
    runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"

    Jintal Patel

    N B 2 Replies Last reply
    0
    • J Jintal Patel

      i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.

      function textboxMultilineMaxNumber(txt,maxLen){
      try{
      if(txt.value.length > (maxLen-1))return false;
      }catch(e){
      }
      }
      runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"

      Jintal Patel

      N Offline
      N Offline
      Naik A2Ze
      wrote on last edited by
      #2

      Hi, Check The Text Box Properties . And Set The Property of Text Box .

      Naik M

      S 1 Reply Last reply
      0
      • J Jintal Patel

        i have try using this code.when i write 100 char (max Length) contineuosly then it will work..but when i m copy some text and paste on that text box at that time it will not be dispaly the error msg.

        function textboxMultilineMaxNumber(txt,maxLen){
        try{
        if(txt.value.length > (maxLen-1))return false;
        }catch(e){
        }
        }
        runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"

        Jintal Patel

        B Offline
        B Offline
        Ballita
        wrote on last edited by
        #3

        If you want ot set maximum length of a multiline textbox, You can use the following code in page load. System.Text.StringBuilder jScriptStr2 = new System.Text.StringBuilder(); jScriptStr2.Append(""); jScriptStr2.Append("function limitText (textObj, maxCharacters){"); jScriptStr2.Append("if (textObj.innerText.length >= maxCharacters){"); jScriptStr2.Append("if ((event.keyCode >= 32 && event.keyCode <= 126) || (event.keyCode >= 128 && event.keyCode <= 254)){"); jScriptStr2.Append("event.returnValue = false;"); jScriptStr2.Append("}}}"); Page.RegisterStartupScript("textLimiter", jScriptStr2.ToString()); And In Html of textbox add OnKeyDown="limitText (this, 500);"

        Thanks & Regards Mishra

        1 Reply Last reply
        0
        • N Naik A2Ze

          Hi, Check The Text Box Properties . And Set The Property of Text Box .

          Naik M

          S Offline
          S Offline
          Sonia Gupta
          wrote on last edited by
          #4

          maxlength does not restricts the user to type only that much length which is defined in the properties in asp.net.

          Soniagupta1@yahoo.co.in

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups