Key press Event in asp.net
Hi Experts...Can any body send me peace of code that how to use keypress event in asp.net plz..thanks in advance..
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
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 5, 2011, 12:31 AM EST
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onkeypress", "javascript:return allownumbers(event);");
}
}
Thanks
Shivaraj Poojary69 reputationPosted Dec 5, 2011, 12:40 AM EST
Prashant ChaudharyRank #1,151 · 1.6K reputationPosted Dec 5, 2011, 1:45 AM EST
string s =e.Key.ToString();
char[] chars = s.ToCharArray();
char chr = chars[0];
Console.WriteLine (System.Convert.ToInt32(chr));
You can use this to do so