Solved

ASP.net field validation

Posted on 2013-01-24
4
212 Views
Last Modified: 2013-02-15
How do you avoid a user entering more then one word into a text box in asp.net?  Let's say that they can only list 1 word or combination of words but there can be no character spaces between each word?  How would you handle this in ASP.NET?  Thanks!
0
Comment
Question by:VBBRett
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
duttcom earned 500 total points
ID: 38816704
You could add this to your textbox -

onKeyDown="return (event.keyCode!=32);"

As in-

<asp:TextBox ID="CountIDTextBox" runat="server" onKeyDown="return (event.keyCode!=32);"></asp:TextBox>

And then no spaces can be typed into that textbox.
0
 

Author Comment

by:VBBRett
ID: 38816726
Is this C# code or a script?
0
 
LVL 12

Assisted Solution

by:duttcom
duttcom earned 500 total points
ID: 38816742
That's javascript, but it works perfectly in an asp page as per the example.

You can also use onKeyDown="return (event.keyCode!=13);" which will disable the enter key to prevent accidental postback if someone hits the enter key in a textbox.
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38817733
Does this work cross browser?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now