Solved

Unable to find textbox keypress event in ASP.NET

Posted on 2004-03-26
6
15,779 Views
Last Modified: 2011-08-18
I want to trap the keypress event of a textbox in a web page developed in ASP.NET. How will I do it.
 
0
Comment
Question by:sam78_my
6 Comments
 
LVL 4

Accepted Solution

by:
JNSTAUB earned 168 total points
ID: 10685996
it may be:
<asp:TextBox onTextChanged="myTextHandler" runat="server" />
or a client script
post back at each keystrokes is bandwidth consumming!!!
0
 
LVL 1

Assisted Solution

by:youroun
youroun earned 166 total points
ID: 10686515
as above, you could add a server event to detect key press, wouldn't do that, cuz it's bandwith consuming...
It's better to add client side code, in order for it to work though, you have to add the client event in your server script:

private void Page_Load(object sender, System.Eventargs e)
{
   textBox1.Attributes.Add("onkeypress", "javascriptFunctionHere()");
}

and in your client page add the function:

<script language=javascript>
   function javascriptFunctionHere()
   {
      alert('do something here, like show this message');
   }
</script>

client side script works most of the time, can't see of any reason why to do a postBack on every keypress ...
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 166 total points
ID: 10686704
Sub Page_Load( ByVal sender As System.Object, ByVal e As System.EventArgs)
            txtTextbox.Attributes.Add("onKeyPress", _
                  "JavaScript:HandleOnKeyPress()")
End Sub
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question