Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this code
Private void txtnumber_KeyPress(Object sender,KeyPressEventArgs e)
{
     if(!char.IsNumber(e.Keychar))
      {
          e.Handled =true;
      }
}


to filter user data is be number .So this codes can not use in C# Web.
How can I do?please help me
Posted
Updated 16-Jul-11 0:02am
v2

 
Share this answer
 
Comments
Tarun.K.S 17-Jul-11 7:42am    
Excellent. 5+
Espen Harlinn 17-Jul-11 8:00am    
Thank you, Karun!
thatraja 17-Jul-11 7:56am    
Looks like I must learn jQuery quickly. Today found more than couple of jQuery questions. 5!
Espen Harlinn 17-Jul-11 8:00am    
Thank you, thatraja :)
Please have a look at these discussions:

1 - http://www.dotnetspider.com/forum/3606-how-can-i-get-key-press-event-asp-net-C.aspx[^]. This one is regarding entering for numbers only.

2 - http://forums.asp.net/t/1124980.aspx/1?ASP+NET+TextBox+KeyPress+Event[^]

Hope this helps. :thumbsup:
 
Share this answer
 
Comments
thatraja 16-Jul-11 9:54am    
Good links, 5!
Tarun.K.S 16-Jul-11 10:04am    
Thanks a lot thAtRaja! :P
thatraja 17-Jul-11 7:55am    
I'm going to pull you too to the prison.
Espen Harlinn 17-Jul-11 7:39am    
Nice reply, my 5
Hi,

Please write following (.aspx)
XML
<SCRIPT LANGUAGE="JavaScript">
function checkNumber(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        //This field accepts numbers only.
        return false
    }
    return true
}
</SCRIPT>


Please write following in (.aspx.cs)
C#
Page_Load(..)
{
   if(!isPostBack)
   {
        txtnumber.Attributes.Add("onkeypress","return checkNumber(event)");
   }
}


Thanks,
Imdadhusen
 
Share this answer
 
v2
Comments
thatraja 16-Jul-11 9:54am    
Clean, 5!

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