Solved

ASP.net field validation

Posted on 2013-01-24
4
214 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get the web content with different encodings 2 45
Split in Javascript 5 39
List<PaisEntity> - show some 1 24
insert value of checklistbox checked 4 26
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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