Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unable to find textbox keypress event in ASP.NET

Posted on 2004-03-26
6
Medium Priority
?
15,785 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 672 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 664 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 664 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…
Suggested Courses

730 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