i have a form with two modes
one that allows edit (value of text box)
and another mode for (non-manager) user – code behind adding “READONLY” to the TextBox tag.
so with the readonly ‘mode’ there’s no input accepted in text box at all
my question is how could i execute validation method based on “READONLY” property of text box ?
strRo = “READONLY” on a condition
<asp:TextBox ID="txtNumbers" runat="server" <%=strRo %> onkeypress="return allowonlynumbers();" />
javascript function
function allowonlynumbers() {
if (event.keyCode >= 48 && event.keyCode <= 57) {
return true;
}
else {
alert('Only numbers can be entered');
return false;
}
}
You would need to pass a reference to the element in your function call, so change the
onkeypressto this:Then, your function needs to be like this:
And the logic you can use is: