Search code examples
asp.netvb.nettextboxvisual-studio-express

VS2012 Express Textbox missing KeyPress event


Been searching this for a while now.

Want to be able to trigger the KeyPress event of my Textbox, but I'm not able to. I've been searching for a while now, saw things as 'add system.windows.forms dll'.. So I added to the top of my page:

Imports System.Windows.Forms

But still the same error..'

I'm working here with 'Microsoft Visual Studio Express 2012 for Web' and I'm creating a normal aspx-website. Is this not possible here to trigger that event or am I missing something?

I'm able to trigger the 'textchanged' event, but that's not what I'm looking for because that seems only to trigger my function when the textbox lost the focus..

enter image description here

A little help here please..


Solution

  • There is no KeyPress event when you're working with an ASP.NET program. If you look at the articles returned from https://www.google.com/#q=asp.net+keypress+event+textbox then you will see that they use JavaScript on the client.

    Depending on why you want to intercept every keypress, you may be able to implement the desired functionality in JavaScript. You could use AJAX to send a message to the server every time a key is pressed, but the user experience of relatively slow typing or things happening out of sync with what they are typing could be undesirable.

    You should remove the reference to System.Windows.Forms.