Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Write Coding So that, a text Box will not take any space between two letters
Posted
Comments
AmitGajjar 16-Sep-12 1:52am    
Homework ?
Sandeep Mewara 16-Sep-12 11:31am    
It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.

Try this one. It will Disable your Space bar on appropriate textbox:

Use this Javascipt Function on client side code.By this you can You can stop Space to be entered:
C#
function CheckNemericValue()
       {
       if(event.keyCode == 32)
       {
       event.keyCode = 0;
       return false;
       }
       }


and then on page_load event use this ;
TextBox1.Attributes.Add("onkeypress", "return CheckNemericValue(event);") 
//It will Disable the Space Bar functionality on TextBox1


But Beware! it will not work on that text which copied and paste into this textbox.
For this problem use this code:
 <asp:TextBox ID="TextBox1" runat="server" onblur="javascript:value=value.replace(/\s/g,'');"></asp:TextBox>
//it remove spaces from textbox's text in onblur event
 
Share this answer
 
v3
Hi,

You can use onKeyPress event to handle such thing. you need to check if entered key is space then ignore it otherwise write in the textbox.

Check MSDN OnKeyPress[^]

Hope it will help you to do your homework.
 
Share this answer
 
Hi,
you also can use this code :
VB
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    If e.KeyChar = " " Then
        e.KeyChar = Nothing
    End If
End Sub



nice one :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900