Solved

Unable to find textbox keypress event in ASP.NET

Posted on 2004-03-26
6
15,784 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

627 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