Introduction :

Hi, Here i will explain how to Avoid user to Enter Space in the Textbox using JavaScript, In previous Tutorials i have explained you How to Make Textbox Readonly and How to allow only numbers in JavaScript. Here to i use Keycode Values in keypress event to execute the function. Also blocked pasting the values into TextBox

Aspx and JavaScript code :
<head runat="server">
    <script type="text/javascript">
        function AvoidSpace() {
            if (event.keyCode == 32) {
                event.returnValue = false;
                return false;
    <form id="form1" runat="server">
        <asp:TextBox ID="txt1" runat="server" onpaste="return false;" onkeypress="AvoidSpace()"></asp:TextBox>