locked
Multiline textbox Maxlength problem RRS feed

  • Question

  • User1949879671 posted

    hi

    i m using the textbox of address with textmode="multiline"

    but now when i set its maxlength = 150

    it doesnt set the maxlength and take max arguments

    how do i set maxlength with multiline proparty?

    thanks in advanve.

    shweta

     

    Wednesday, June 25, 2008 1:10 AM

Answers

  • User-219472588 posted

    hi shweta,

    u can use this javascript function

    function setMaxLength(obj, intLen)
    {
     if (obj.getAttribute && obj.value.length > intLen)
     {
      obj.value=obj.value.substring(0,intLen);
      alert("Maximum " + intLen + " characters are allowed!");
     }
    }

     

    now in code behind in Page_Load method add this line

    MultilineTextBox.Attributes.Add("onkeyup","setMaxLength(this,150);")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 25, 2008 1:31 AM
  • User1949879671 posted

    thanks its done

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 25, 2008 2:10 AM

All replies

  • User1766772294 posted

    This isn't a limitation of ASP.Net. It's a limitation of the HTML TextArea element. It doesn't support the concept of "Max Length". Your best bet is to use CustomValidator to verify the length before saving.

    Wednesday, June 25, 2008 1:28 AM
  • User-219472588 posted

    hi shweta,

    u can use this javascript function

    function setMaxLength(obj, intLen)
    {
     if (obj.getAttribute && obj.value.length > intLen)
     {
      obj.value=obj.value.substring(0,intLen);
      alert("Maximum " + intLen + " characters are allowed!");
     }
    }

     

    now in code behind in Page_Load method add this line

    MultilineTextBox.Attributes.Add("onkeyup","setMaxLength(this,150);")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 25, 2008 1:31 AM
  • User1949879671 posted

    thanks its done

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 25, 2008 2:10 AM