troubleshooting Question

the 254 character limit on the text boxes is not working

Avatar of Codeaddict7423
Codeaddict7423Flag for United States of America asked on
C#ASP.NETWeb Applications
1 Comment1 Solution403 ViewsLast Modified:
guru sami,

The comment boxes on this form appear not work to limit the number of characters allowed:
My code behind is as follows:
--------
 protected void ServerValidateDesc(object source, ServerValidateEventArgs args)
    {

        if (args.Value.Length >= 255)

        { args.IsValid = false; }

        else { args.IsValid = true; }

    }

---------
the javascript code is as follows:
-----
<
 function textboxMultilineMaxNumber(txt,maxLen){  
            try{  
                if(txt.value.length > (maxLen-1))
                return false;  
               }catch(e){  
               }  
        }  


-----

The control code that calls the javascript character limit is as follows:
--------
 <!--Park Owner Begins -->
                             
         <tr>
         
          <td style="width:30%; text-align:right; vertical-align:top"><asp:Label ID="Label6" runat="server" Text="Park Owner:"></asp:Label>&nbsp;&nbsp; <br /> </td>
          <td style="width:70%; text-align:left; vertical-align:top">
           
<asp:TextBox ID="txtParkOwner" runat="server" onkeypress="return textboxMultilineMaxNumber(this,254)" Rows="4" Columns="36" TextMode="MultiLine" Text='<%# Bind("PARK_Owner") %>'></asp:TextBox>
<span style="color: red">&nbsp;*&nbsp;</span>

<asp:RequiredFieldValidator ID="RFV_ParkOwner" runat="server" ControlToValidate="txtParkOwner" Display="Dynamic" ErrorMessage="Park Owner is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>


</td>
                                                   
                                               
                            </tr>
                             <!--Park Owner Ends -->
----

Can you please  help?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros