Wednesday, September 16, 2009

restrict Backspace and Delete in textbox

// This is for the Key Press Event
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;
} And in your aspx call the keypress as

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