Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i did't find the keypress event for the aspx textbox, i want this event in .cs page.some one help me.
Posted

The code in a .cs file is ran on the server. If you want to handle client side code, which a key press is, you'll need JavaScript. You can also look into the AJAX.NET framework.
 
Share this answer
 
You can use the onkeypress Event in JavaScript.
Here is a sample

ASP.NET
<asp:textbox id="Textbox1" runat="server" ></asp:textbox>


Javascript function to be called on KeyPress event
JavaScript
function Samplefunction()
    {
        alert('You have pressed a key inside the textbox');
    }


In your code behind file you can call the javaScript function using the below line.
C#
Textbox1.Attributes.Add("onkeypress", "Samplefunction()");

When ever you enter some text in the textbox an alert message pops up.
Refer this link for more information on KeyPress event
onkeypress Event[^]

Hope this helps.
 
Share this answer
 
v2

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