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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
vivek kulkarni132 reputationPosted Apr 15, 2009, 6:48 AM EDT
Hi,
You need to handle it on the client side. here is a sample.
<%@ Page Language="C#" %>
Thank you,
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 15, 2009, 7:46 AM EDT
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
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Apr 15, 2009, 9:02 PM EDT
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