Answered How to limit the number of characters in a Text Box

  • Saturday, May 19, 2012 3:27 PM
     
     

    Hi,

    I need to limit the number of characters that can be typed by the user in a Text Box.  I do not want an error message, I need to physically restrict the user to type in more characters than what is required. I know the following code is required, but where do I use this code:

    TextBox txtBox = new TextBox();

    txtBox.MaxLengh = [Your Restriction];

    Kind Regards,

All Replies

  • Saturday, May 19, 2012 3:40 PM
     
     Proposed Answer Has Code
    Namespace LightSwitchApplication
    
        Public Class YourScreen
    
            Private Sub YourScreen_Created()
                ' Write your code here.
                Me.FindControl("myControl").SetProperty("MaxLength", 50)
            End Sub
        End Class
    
    End Namespace


    It's your story - time to switch on the innovation. || About me || LightSwitch blog

    • Proposed As Answer by c4ctopus Tuesday, June 26, 2012 11:57 AM
    •  
  • Saturday, May 19, 2012 3:43 PM
     
     

    Hi

    You can restrict the no. of character from the built-in lightswitch entity designer. From entity designer click on your property and then click on your properties. Please see the image.

    You can also use Mask TextBox from free DevExpress DXEditor LightSwitch control. This will help you to prevent entering of no. of character.

    Regards


    Rashmi Ranjan Panigrahi

  • Saturday, May 19, 2012 3:45 PM
     
     
    Thank you Jan.  Do you possibly have the C# Code for this?
  • Saturday, May 19, 2012 4:00 PM
     
     

    Thank you Rashmi,

    I have previosuly downloaded and installed DXEditor and I have enabled it now.  My problem is not to prevent the entering of the incorrect number of chracters, but rather to physically restrict the user to type in more characters that he is supposed to enter.  e.g. The editor will stop at 10 characters rather than allowing more but display an error messgae.

    So in essence I would like the user only to type in a maximum of 10 chracters and then the editor should not take anymore characters.  Do you possibly know how I can use the Mask in DXEditor to do this?

    Kind Regards, 

  • Saturday, May 19, 2012 4:02 PM
     
     Answered Has Code

    Should be

     this.FindControl("myControl").SetProperty("MaxLength", 50)

    in c #


    It's your story - time to switch on the innovation. || About me || LightSwitch blog

    • Proposed As Answer by Jewel Lambert Sunday, May 20, 2012 2:19 PM
    • Unproposed As Answer by SpoedNick Sunday, May 20, 2012 2:41 PM
    • Marked As Answer by SpoedNick Sunday, May 20, 2012 2:41 PM
    •