The type or namespace name 'KeyPressEventArgs' could not be found

G

Guest

What do I have to import at the top of my aspx page (c#) when getting this
error message?

i tried <% Import namespace="System.Windows.Forms.KeyPressEventArgs"%>

but it erros something along the lines of 'Windows not recognised in System'
I'm not sure I understand how to include classes. I'm only trying to
recognise an enter key pressed in a text box.
 
K

Karl Seguin

Louise,
You seem to be trying to mix WinForms and WebForms, which you can't. The
Textbox in asp.net is an instance of System.Web.UI.WebControls.TextBox,
which is not the same as in winforms (System.Windows.Forms.TextBox). The
ASP.Net one doesn't expose a KeyPress event, and if it did, the event
argument surely wouldn't be found in System.Windows.Forms*, but rather in
System.Web.UI.*

System.Web.UI.TextBox exposes a TextChanged event and that's pretty much it.
If you want to catch OnKeyPress you'll need to use javascript on the client.

The error you are getting is because you didn't reference
System.Windows.Forms to your code, which defines the System.Windows*
namespace. As such, System.Windows* is unrecognized. Again, simply adding
the reference might remove that error, but it won't work like you want
(winforms != webforms).

Karl
 
K

Kikoz

Hi Louise.

If you try to develop a web site using asp.net then please describe in more
details what you're trying to do. None of asp.net controls have KeyPress or
KeyUp or KeyDown events. If you develop a desktop app (as your use of
System.Windows.Forms namespace implies) than you're in a wrong newsgroup :)

Regards,
Kikoz
 
G

Guest

didnt realise you couldnt use these events such as keypress on server
controls. makes sense as they are client events. sorry will think more in
future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top