[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ASP.net field validation

Posted on 2013-01-24
4
Medium Priority
?
222 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 2000 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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