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.
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.
Satyapriya NayakPosted Dec 5, 2011, 5:31 AM
<%@ 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
Prashant ChaudharyPosted Dec 5, 2011, 6:45 AM
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
Shivaraj PoojaryPosted Dec 5, 2011, 5:40 AM