Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

i have a asp.net textbox in gridview control problem im having is that "onkeypress" event is not working in IE when user pres DEL key from keyboard its working on other keys my code is as follows

XML
<asp:TextBox CssClass="InputBox"  onkeypress="return isValidKey(event)" ID="txtRefundAmount" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Amount") %>'></asp:TextBox>


C#
function isValidKey(e) {
            return false;
        }


i just simply want to prevent user from modifying textbox value. this can be done by setting textbox property readonly=true or enable=false but in my case another java script function is updating value this textbox and if i make it readonly or disable updated value at run time is not posted on server when saving data
Posted

1 solution

try this

HTML
function isValidKey(e) { 
    
  var charCode = e.keyCode || e.which;     
  if (charCode == 8 || charCode == 46)         
      return false;      

return true; 
}  

<input id="tb_box" onkeydown="return isValidKey(event)" type="text" /> 
 
Share this answer
 
Comments
kashif Atiq 7-Feb-12 2:13am    
thanks zyck i have already found the solution on internet that onkeypress will not work on IE in my case so i have to use onkeydown event as mentioned in your answer.
anyways thanks for the reply
zyck 7-Feb-12 2:54am    
oki thanks

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