7 February 2014

Restrict space in textbox using JavaScript


Below JavaScript code used to restrict the space in the textbox
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Restrict space in textbox using JavaScript.aspx.cs" Inherits="Restrict_space_in_textbox_using_JavaScript" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script type="text/javascript">
         function DisableSpace() {
             if (event.keyCode == 32) {
                 event.returnValue = false;
                 return false;
             }
         }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
        <asp:TextBox ID="txtLoginID" onkeypress="return DisableSpace()" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnLogin" runat="server" Text="Login" />
    </div>
    </form>
</body>
</html>
 



 

No comments:

Post a Comment