The solution is to put the JavaScript at the Read Only Text Box to prevent page from go back to previous page.
The Script
function preventBackspace(e) {
var evt = e || window.event;
if (evt) {
var keyCode = evt.charCode || evt.keyCode;
if (keyCode === 8) {
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
alert("This is a read only field");
} }
else {
evt.returnValue = false;
alert("This is a read only field");
}
}
else
{
evt.returnValue = false;
alert("This is a read only field");
}
}
Example to call js function
<asp:TextBox ID="TextBox1" ReadOnly="true" onKeyDown= "preventBackspace();" runat="server"> </asp:TextBox>
so if user click on the readonly textbox and try tu enter backspace key, the alert message will show .
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

I have a field that i dynamically set to readonly depending on certain condition. Now this message appears even when the field at that time is not readonly. How does one prevent that? Thanks
ReplyDeleteSipho