0

I am trying to avoid spaces in the Textbox and prevent the user to enter any spaces. I tried

<ajaxToolkit:FilteredTextBoxExtender ID="Filteredtextboxextender2" runat="server"
                                FilterType="Custom" InValidChars=" "
                                TargetControlID="tx_username">
                            </ajaxToolkit:FilteredTextBoxExtender>

but it didn't work. Is there any other solutions ?

3
  • What issue do you have? Did the extender forbid all characters? Did it allow everything, including spaces? Commented Sep 19, 2013 at 18:42
  • no it is javascript error Commented Sep 19, 2013 at 18:43
  • Can you please specify the error message? Commented Sep 19, 2013 at 18:45

2 Answers 2

3

You need client side validation please check all the options available for you:

http://msdn.microsoft.com/en-us/library/yb52a4x0(v=vs.100).aspx

also if I were you I would just use something like this:

$("#username").keypress(function(e) {
     if(e.which == 32) {
        e.preventDefault();
     }
})

which requires jQuery of course you can use pure Javascript if you like :)

Sign up to request clarification or add additional context in comments.

Comments

2

According to the docs, you must set FilterMode="InvalidChars"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.