Jonathan Small
Jonathan Small

Reputation: 1099

TextBox does not have KeyDown or KeyPress events

I have a visual basic web application and i placed a textbox on the form. When I look at the actions available for that textbox, the only actions available are DataBinding, Disposed, Init, Load, PreRender, TextChanged, and Unload. Why is KeyDown not available? Is it because this is a web application as opposed to a windows application? Is it possible to build an event handler that will fire the when a key is pressed? Maybe I have to convert my project to a windows application?

Upvotes: 0

Views: 803

Answers (3)

Jaime Herrera
Jaime Herrera

Reputation: 46

Why do you want to capture the keystroke?

You can control that the TextBox is entered by code, for example, that only numbers are entered;

asp:TextBox ID="TextBox3" runat="server" Width="50px" AutoComplete="off" MaxLength="20" type="number" step="any" TabIndex="9">

Upvotes: 0

T.S.
T.S.

Reputation: 19404

You are using Asp.Net Web Forms application. The very reason it exists is to help developers who previously worked on WinForms applications to move towards Web Development. This is why there are some similarities, e.g. WinControls <-> WebControls. But don't forget, you are in the WEB now. Your Button_onClick event works completely differently. If on WinForms this is invoked directly by button press; on the WebForms, your form is translated into HTML page with <form> and <input . . .> tags. And it builds javascript automatically, so when you press the button, there is a POST call to a server. Then, your server receives request, and directs execution to Button_onClick during so-called "page cycle".

Once you decide that your app needs to be a web app, you should probably forget doing it using Web Forms because this system is not true web development. A true web-centric development would be Javascript-based UI, may be using some framework like Vue or Angular with Asp.net Web Api as server app. May be you should start with Asp.net MVC. This will make you concentrate on single application, because server and client components are developed together when you use MVC.

Going back to main question - yes, 2 different systems, do not expect compatibility. And even when something seem similar, they might behave differently.

Upvotes: 0

jmcilhinney
jmcilhinney

Reputation: 54487

Yes, that is the reason. Remember that, in a web application, functionality is split between server and client. If you want to react to keystrokes then you need to do that on the client side, which means using JavaScript.

Upvotes: 2

Related Questions