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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • louise raisbeck

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

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

    i tried <% Import namespace="Syst em.Windows.Form s.KeyPressEvent Args"%>

    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.
  • Karl Seguin

    #2
    Re: The type or namespace name 'KeyPressEventA rgs' could not be found

    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.W ebControls.Text Box,
    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.T extBox 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

    --
    MY ASP.Net tutorials
    Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



    "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> wrote in
    message news:D10BE9D2-DCCC-47BE-B5E0-B35D60FE729B@mi crosoft.com...[color=blue]
    > What do I have to import at the top of my aspx page (c#) when getting this
    > error message?
    >
    > i tried <% Import namespace="Syst em.Windows.Form s.KeyPressEvent Args"%>
    >
    > but it erros something along the lines of 'Windows not recognised in[/color]
    System'[color=blue]
    > I'm not sure I understand how to include classes. I'm only trying to
    > recognise an enter key pressed in a text box.[/color]


    Comment

    • Kikoz

      #3
      Re: The type or namespace name 'KeyPressEventA rgs' could not be found

      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


      "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> wrote in
      message news:D10BE9D2-DCCC-47BE-B5E0-B35D60FE729B@mi crosoft.com...[color=blue]
      > What do I have to import at the top of my aspx page (c#) when getting this
      > error message?
      >
      > i tried <% Import namespace="Syst em.Windows.Form s.KeyPressEvent Args"%>
      >
      > 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.[/color]


      Comment

      • louise raisbeck

        #4
        Re: The type or namespace name 'KeyPressEventA rgs' could not be fo

        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.

        "Kikoz" wrote:
        [color=blue]
        > 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
        >
        >
        > "louise raisbeck" <louiseraisbeck @discussions.mi crosoft.com> wrote in
        > message news:D10BE9D2-DCCC-47BE-B5E0-B35D60FE729B@mi crosoft.com...[color=green]
        > > What do I have to import at the top of my aspx page (c#) when getting this
        > > error message?
        > >
        > > i tried <% Import namespace="Syst em.Windows.Form s.KeyPressEvent Args"%>
        > >
        > > 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.[/color]
        >
        >
        >[/color]

        Comment

        Working...