Skip to main content

Make TextBox Readonly In JavaScript at Keypress Event.

Introduction :

 Hi, Here I will explain how to make TextBox Readonly without using Readonly Property in JavaScript or else in ASP. This Script Coding works Fine in 'KeyPress' Event of the TextBox.
Here Keycode is used for Catching the Keyboard events.Finally this TextBox allows Nothing as a Input even after key is pressed. haven't need any Ajax controls to implement it.

Aspx and javaScript:

<head runat="server">
    <script type="text/javascript">
        function AvoidWrite(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode < 48 || charCode > 57)
                return false;
            else {
                return false;
    <form id="form1" runat="server">
    <asp:TextBox ID="txt1" runat="server" onpaste="return false;" onkeypress="return AvoidWrite(event);" ></asp:TextBox>


  1. I am happy to find this post Very useful for me, as it contains lot of information

    Article submission sites

  2. A good blog for the people who really needs information about this.
    Good work keep it up.

    Article submission sites

  3. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    JavaScript Training in Chennai

    JavaScript Training in Chennai


Post a Comment