Results 1 to 5 of 5

Thread: [RESOLVED] Set MaxLength on form Load

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved [RESOLVED] Set MaxLength on form Load

    Hi,

    Does anyone know how to populate the maxlength property of an asp:textbox on page load?

    I'm getting the value from the my config table in my DB

    When I try setting myControl.MaxLength=10 in the onload event
    It's not written to the control and when I enter text I'm not restricted at all

    I've also tried

    VB Code:
    1. <asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="[HL="#FFFF00"]<%=SummaryLimit%>[/HL]"></asp:textbox>
    2.  
    3. ' And
    4.  
    5. <asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="[HL="#FFFF00"]<%=Convert.ToInt32(SummaryLimit)%>[/HL]"></asp:textbox>
    Geting error - <%=SummaryLimit%> is not a valid value for Int32.
    And
    <%=Convert.ToInt32(SummaryLimit)%> is not a valid value for Int32.

    SummaryLimit Value is declared and assigned as an Int32
    VB Code:
    1. Dim m_iSummaryLimit As Int32 = 250
    2.  
    3. Public Property SummaryLimit() As Int32
    4.         Get
    5.             Return Convert.ToInt32(m_iSummaryLimit)
    6.         End Get
    7.         Set(ByVal Value As Int32)
    8.             m_iSummaryLimit = Convert.ToInt32(Value)
    9.         End Set
    10. End Property

  2. #2
    Member basilisk's Avatar
    Join Date
    Jan 2002
    Posts
    32

    Re: Set MaxLength on form Load

    The textbox control when in multiline mode actually renders as a HTML textarea therefore on a textarea there is no maxlength property so maxlength does not work. One of the ways to control this is to use javascript instead.

  3. #3

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Set MaxLength on form Load

    Basilisk,

    Thanks for that, just wasted the whole morning trying to get it working.

    Cheers Al

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: [RESOLVED] Set MaxLength on form Load

    I did want to pipe in and say that when you use the following:

    <%= ... %>

    in an item tag, you need to surround it with single quotes - ' - and not double quotes - " -.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: [RESOLVED] Set MaxLength on form Load

    Lord Rat,

    Thanks, feel free to pop out of your cave with useful tips like that at anytime

    Cheers Al

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width