How to handle key press events in asp.net c#, i knoe this to handle in windows applications there are events to use directly
but how in asp.net website
Any urls to reffer plsss tell me
thanks,
pramod
How to handle key press events in asp.net c#, i knoe this to handle in windows applications there are events to use directly
but how in asp.net website
Any urls to reffer plsss tell me
thanks,
pramod
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Apr 16, 2009, 1:02 AM
Along with that,you can refer the following URL:
1.http://www.dotnetspider.com/forum/47359-Keypress-event-ASP-Net.aspx
2.http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=3606
3.http://forums.devshed.com/net-development-87/how-to-code-for-key-press-event-in-asp-net-365822.html
Vijaya KadiyalaPosted Apr 15, 2009, 11:46 AM
You should use cliend side script to restrict user to enter some value.
Here is the code:
Enter the filter condition and on code bvehind page load, add the keypress event
to the element by:
TextBox1.Attributes.Add("keypress","return PrecessKeyAlfaNumeric(this,event");
function PrecessKeyAlfaNumeric( textBox, textEvent )
Paste this code in aspx file within scriipt tag.
/*------------------------------------------------------------------------
Purpose: Restricts the text field to Alpha numeric
Inputs : Text field object, event object
Returns: Bool
-------------------------------------------------------------------------*/
{
var code = textEvent.which; // Netscape Method
if (code == null)
{
//alert("Null code");
code = textEvent.keyCode;//IE 4 Method
}
//alert("Got It data=" + code +" value="+textBox.value);
if(!( (code >= 48 && code <= 57) || (code == 8) ||
(code >= 65 && code <= 90) ||
(code >= 97 && code <= 122)))
{
return false;
}
return true;
}
Thanks -- Vijaya Kadiyala
www.DotNetVJ.com
vivek kulkarniPosted Apr 15, 2009, 10:48 AM
Hi,
You need to handle it on the client side. here is a sample.
<%@ Page Language="C#" %>
Thank you,