Thursday, July 3, 2014

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