Click here to Skip to main content
15,036,441 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

In my aspx page one text box is there. I want to disable "Backspace" button functionality for specific text box.

Thanks and Regards,
Murali.
Posted

   
v2
hi dear,

check this solution.

C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 8)
            {
                e.Handled = true;
            }
        }
   
I tried like this it's working fine.

JavaScript
<script type ="text/javascript">
    function Keypress_Event() {
        // This is for Getting the Source Element..
        var objTxtBox = window.event.srcElement;
        // declare the variable for the bool value.
        var isOk = false;
        // Here we need not backspace keycode = 8 and the delete keycode 46
        isOk = (event.keyCode == 8 || event.keyCode == 46) ? false : true; event.returnValue = isOk;
    }
</script>


asp:TextBox ID="txtTest" runat="server" onkeydown="Keypress_Event()"
   

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