Click here to Skip to main content
15,891,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have text box in that user has to enter description. In that text box user enter text should not be less than 50 character.if it is less than it show error that "Description shouldn't be less than 50 characters". In text box user can enter max value in text box beacuse i m set column property max in database.so there will be no limit.
Posted
Updated 4-Apr-13 3:19am
v2
Comments
Anuja Pawar Indore 4-Apr-13 10:22am    
Use Maxlength property of textbox
Prathap Gangireddy 4-Apr-13 14:24pm    
Try to find the length of the text entered in the textbox when the control leaves the textbox i.e. Textbox leave event and show popup using Javascript.

C#
<asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown">
<asp:regularexpressionvalidator display="Dynamic" controltovalidate="TextBox2" id="RegularExpressionValidator2" validationexpression="^[\s\S]{50,}$" runat="server" errormessage="Minimum 50 characters required." xmlns:asp="#unknown">
 
Share this answer
 
v3
C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace skmExtendedValidators
{
   [ToolboxData("<{0}:TextBoxLengthValidator runat=server
         ErrorMessage=\"TextBoxLengthValidator\"></{0}:TextBoxLengthValidator>")]
   public class TextBoxLengthValidator : BaseCompareValidator
   {

      // Properties
      [Bindable(true),
       Description("TextBoxLengthValidator_MaximumLength"),
       Category("Behavior"),
       DefaultValue(-1)]
      public int MaximumLength
      {
         get
         {
            object MaxLengthVS = this.ViewState["MaximumLength"];
            if (MaxLengthVS != null)
            {
               return (int) MaxLengthVS;
            }
            return -1;
         }
         set
         {
            this.ViewState["MaximumLength"] = value;
         }
      }

      protected override bool EvaluateIsValid()
      {
         if (this.MaximumLength < 0)
            return true;

         string ControlToValidateName =
             base.GetControlValidationValue(base.ControlToValidate);

         return ControlToValidateName.Length <=
                   System.Convert.ToInt32(this.MaximumLength);
      }

      ...
   }
}
 
Share this answer
 
Comments
fjdiewornncalwe 4-Apr-13 14:20pm    
My 3. Your solution would work, but I don't like it when unnecessary hits go back to the server for validation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900