Solved

ASP.net field validation

Posted on 2013-01-24
4
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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