Hitting Enter in a textbox

Discussion in 'ASP .Net' started by Nate Hekman, Sep 23, 2004.

  1. Nate Hekman

    Nate Hekman Guest

    As I've mentioned a couple of times in the last few minutes(!), I've got a
    simple form with an edit box and a Submit button. If I type something in
    the Edit box and hit Enter I hear a click but nothing happens. If I click
    on the Submit button its Click event fires as I'd expect. If I click
    anywhere else on the web page and then hit Enter, the button's Click event
    fires too.

    I want the Click event to fire when the user is in the Edit box and hits
    Enter. How can I do this?

    Thanks for your help.


    Nate Hekman
    Calgary, Alberta, Canada
    Nate Hekman, Sep 23, 2004
    #1
    1. Advertising

  2. Nate Hekman

    Curt_C [MVP] Guest

    Is it single line or multiline? If it's multiline it's by design.
    You can use clientside code to catch the ENTER press event and call the
    button click.

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    Site: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "Nate Hekman" <> wrote in message
    news:%...
    > As I've mentioned a couple of times in the last few minutes(!), I've got a
    > simple form with an edit box and a Submit button. If I type something in
    > the Edit box and hit Enter I hear a click but nothing happens. If I click
    > on the Submit button its Click event fires as I'd expect. If I click
    > anywhere else on the web page and then hit Enter, the button's Click event
    > fires too.
    >
    > I want the Click event to fire when the user is in the Edit box and hits
    > Enter. How can I do this?
    >
    > Thanks for your help.
    >
    >
    > Nate Hekman
    > Calgary, Alberta, Canada
    >
    >
    Curt_C [MVP], Sep 23, 2004
    #2
    1. Advertising

  3. Nate Hekman

    Nate Hekman Guest

    It's single line. And it does reload the page--I can put a breakpoint in
    Page_Load and it breaks when I hit Enter, but it doesn't call
    btnSubmit_Click.

    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:%...
    > Is it single line or multiline? If it's multiline it's by design.
    > You can use clientside code to catch the ENTER press event and call the
    > button click.
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > Site: http://www.Darkfalz.com
    > Blog: http://blog.Darkfalz.com
    >
    >
    > "Nate Hekman" <> wrote in message
    > news:%...
    >> As I've mentioned a couple of times in the last few minutes(!), I've got
    >> a simple form with an edit box and a Submit button. If I type something
    >> in the Edit box and hit Enter I hear a click but nothing happens. If I
    >> click on the Submit button its Click event fires as I'd expect. If I
    >> click anywhere else on the web page and then hit Enter, the button's
    >> Click event fires too.
    >>
    >> I want the Click event to fire when the user is in the Edit box and hits
    >> Enter. How can I do this?
    >>
    >> Thanks for your help.
    >>
    >>
    >> Nate Hekman
    >> Calgary, Alberta, Canada
    >>
    >>

    >
    >
    Nate Hekman, Sep 23, 2004
    #3
  4. You can use some javascript to manage it. Add the javascript using the attributes of the control

    TextBox1.Attributes.Add("onkeydown", "javascript:if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){document.Form1." & Button1.ClientID & ".click();return false;}else return true;")

    (check the name of your HTML form and your controls to get this code to work)

    Hope this helps

    Alan Ferrandiz [MCT]


    "Curt_C [MVP]" <software_AT_darkfalz.com> escribió en el mensaje news:#...
    > Is it single line or multiline? If it's multiline it's by design.
    > You can use clientside code to catch the ENTER press event and call the
    > button click.
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > Site: http://www.Darkfalz.com
    > Blog: http://blog.Darkfalz.com
    >
    >
    > "Nate Hekman" <> wrote in message
    > news:%...
    > > As I've mentioned a couple of times in the last few minutes(!), I've got a
    > > simple form with an edit box and a Submit button. If I type something in
    > > the Edit box and hit Enter I hear a click but nothing happens. If I click
    > > on the Submit button its Click event fires as I'd expect. If I click
    > > anywhere else on the web page and then hit Enter, the button's Click event
    > > fires too.
    > >
    > > I want the Click event to fire when the user is in the Edit box and hits
    > > Enter. How can I do this?
    > >
    > > Thanks for your help.
    > >
    > >
    > > Nate Hekman
    > > Calgary, Alberta, Canada
    > >
    > >

    >
    >
    Alan Ferrandiz [MCT], Sep 23, 2004
    #4
  5. Nate Hekman

    Matt Berther Guest

    Hello Nate,

    I have a post on my website which details how to fix this without any complex javascript, etc.

    http://www.mattberther.com/2003/06/000125.html

    --
    Matt Berther
    http://www.mattberther.com

    > As I've mentioned a couple of times in the last few minutes(!), I've
    > got a simple form with an edit box and a Submit button. If I type
    > something in the Edit box and hit Enter I hear a click but nothing
    > happens. If I click on the Submit button its Click event fires as
    > I'd expect. If I click anywhere else on the web page and then hit
    > Enter, the button's Click event fires too.
    >
    > I want the Click event to fire when the user is in the Edit box and
    > hits Enter. How can I do this?
    >
    > Thanks for your help.
    >
    > Nate Hekman
    > Calgary, Alberta, Canada
    Matt Berther, Sep 23, 2004
    #5
  6. Nate Hekman

    Curt_C [MVP] Guest

    of course not... you didn't call it. You'll have to do some if(IsPostBack)
    in the load_page and call the function(s) that are in the button_click

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    Site: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "Nate Hekman" <> wrote in message
    news:uDe$$...
    > It's single line. And it does reload the page--I can put a breakpoint in
    > Page_Load and it breaks when I hit Enter, but it doesn't call
    > btnSubmit_Click.
    >
    > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    > news:%...
    >> Is it single line or multiline? If it's multiline it's by design.
    >> You can use clientside code to catch the ENTER press event and call the
    >> button click.
    >>
    >> --
    >> Curt Christianson
    >> Owner/Lead Developer, DF-Software
    >> Site: http://www.Darkfalz.com
    >> Blog: http://blog.Darkfalz.com
    >>
    >>
    >> "Nate Hekman" <> wrote in message
    >> news:%...
    >>> As I've mentioned a couple of times in the last few minutes(!), I've got
    >>> a simple form with an edit box and a Submit button. If I type something
    >>> in the Edit box and hit Enter I hear a click but nothing happens. If I
    >>> click on the Submit button its Click event fires as I'd expect. If I
    >>> click anywhere else on the web page and then hit Enter, the button's
    >>> Click event fires too.
    >>>
    >>> I want the Click event to fire when the user is in the Edit box and hits
    >>> Enter. How can I do this?
    >>>
    >>> Thanks for your help.
    >>>
    >>>
    >>> Nate Hekman
    >>> Calgary, Alberta, Canada
    >>>
    >>>

    >>
    >>

    >
    >
    Curt_C [MVP], Sep 23, 2004
    #6
  7. Nate Hekman

    Matt Berther Guest

    Hello Curt_C [MVP]" software_AT_darkfalz.com,

    Whoah... No you dont... The event needs to be hooked up and it will be executed somewhere between OnInit and OnLoad...

    --
    Matt Berther
    http://www.mattberther.com

    > of course not... you didn't call it. You'll have to do some
    > if(IsPostBack) in the load_page and call the function(s) that are in
    > the button_click
    >
    > "Nate Hekman" <> wrote in message
    > news:uDe$$...
    >
    >> It's single line. And it does reload the page--I can put a
    >> breakpoint in Page_Load and it breaks when I hit Enter, but it
    >> doesn't call btnSubmit_Click.
    >>
    >> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    >> news:%...
    >>
    >>> Is it single line or multiline? If it's multiline it's by design.
    >>> You can use clientside code to catch the ENTER press event and call
    >>> the
    >>> button click.
    >>> --
    >>> Curt Christianson
    >>> Owner/Lead Developer, DF-Software
    >>> Site: http://www.Darkfalz.com
    >>> Blog: http://blog.Darkfalz.com
    >>> "Nate Hekman" <> wrote in message
    >>> news:%...
    >>>
    >>>> As I've mentioned a couple of times in the last few minutes(!),
    >>>> I've got a simple form with an edit box and a Submit button. If I
    >>>> type something in the Edit box and hit Enter I hear a click but
    >>>> nothing happens. If I click on the Submit button its Click event
    >>>> fires as I'd expect. If I click anywhere else on the web page and
    >>>> then hit Enter, the button's Click event fires too.
    >>>>
    >>>> I want the Click event to fire when the user is in the Edit box and
    >>>> hits Enter. How can I do this?
    >>>>
    >>>> Thanks for your help.
    >>>>
    >>>> Nate Hekman
    >>>> Calgary, Alberta, Canada
    Matt Berther, Sep 23, 2004
    #7
  8. Nate Hekman

    Nate Hekman Guest

    Well that starts to get pretty messy pretty fast, because of course if you
    DO click the button then first Page_Load gets called, followed by
    btnSubmit_Click. If you also call btnSubmit_Click from Page_Load, it gets
    called twice.

    Matt Berther's fix did the trick for me. Thanks to everyone who offered
    advice.


    Nate

    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:...
    > of course not... you didn't call it. You'll have to do some if(IsPostBack)
    > in the load_page and call the function(s) that are in the button_click
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > Site: http://www.Darkfalz.com
    > Blog: http://blog.Darkfalz.com
    >
    >
    > "Nate Hekman" <> wrote in message
    > news:uDe$$...
    >> It's single line. And it does reload the page--I can put a breakpoint in
    >> Page_Load and it breaks when I hit Enter, but it doesn't call
    >> btnSubmit_Click.
    >>
    >> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    >> news:%...
    >>> Is it single line or multiline? If it's multiline it's by design.
    >>> You can use clientside code to catch the ENTER press event and call the
    >>> button click.
    >>>
    >>> --
    >>> Curt Christianson
    >>> Owner/Lead Developer, DF-Software
    >>> Site: http://www.Darkfalz.com
    >>> Blog: http://blog.Darkfalz.com
    >>>
    >>>
    >>> "Nate Hekman" <> wrote in message
    >>> news:%...
    >>>> As I've mentioned a couple of times in the last few minutes(!), I've
    >>>> got a simple form with an edit box and a Submit button. If I type
    >>>> something in the Edit box and hit Enter I hear a click but nothing
    >>>> happens. If I click on the Submit button its Click event fires as I'd
    >>>> expect. If I click anywhere else on the web page and then hit Enter,
    >>>> the button's Click event fires too.
    >>>>
    >>>> I want the Click event to fire when the user is in the Edit box and
    >>>> hits Enter. How can I do this?
    >>>>
    >>>> Thanks for your help.
    >>>>
    >>>>
    >>>> Nate Hekman
    >>>> Calgary, Alberta, Canada
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Nate Hekman, Sep 23, 2004
    #8
  9. Nate Hekman

    Curt_C [MVP] Guest

    I didn't specifically mean it could ONLY be from the load, just trying to
    say that he needed to put in a catch in the load sequence.....geesh....

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    Site: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "Matt Berther" <> wrote in message
    news:...
    > Hello Curt_C [MVP]" software_AT_darkfalz.com,
    >
    > Whoah... No you dont... The event needs to be hooked up and it will be
    > executed somewhere between OnInit and OnLoad...
    >
    > --
    > Matt Berther
    > http://www.mattberther.com
    >
    >> of course not... you didn't call it. You'll have to do some
    >> if(IsPostBack) in the load_page and call the function(s) that are in
    >> the button_click
    >>
    >> "Nate Hekman" <> wrote in message
    >> news:uDe$$...
    >>
    >>> It's single line. And it does reload the page--I can put a
    >>> breakpoint in Page_Load and it breaks when I hit Enter, but it
    >>> doesn't call btnSubmit_Click.
    >>>
    >>> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    >>> news:%...
    >>>
    >>>> Is it single line or multiline? If it's multiline it's by design.
    >>>> You can use clientside code to catch the ENTER press event and call
    >>>> the
    >>>> button click.
    >>>> --
    >>>> Curt Christianson
    >>>> Owner/Lead Developer, DF-Software
    >>>> Site: http://www.Darkfalz.com
    >>>> Blog: http://blog.Darkfalz.com
    >>>> "Nate Hekman" <> wrote in message
    >>>> news:%...
    >>>>
    >>>>> As I've mentioned a couple of times in the last few minutes(!),
    >>>>> I've got a simple form with an edit box and a Submit button. If I
    >>>>> type something in the Edit box and hit Enter I hear a click but
    >>>>> nothing happens. If I click on the Submit button its Click event
    >>>>> fires as I'd expect. If I click anywhere else on the web page and
    >>>>> then hit Enter, the button's Click event fires too.
    >>>>>
    >>>>> I want the Click event to fire when the user is in the Edit box and
    >>>>> hits Enter. How can I do this?
    >>>>>
    >>>>> Thanks for your help.
    >>>>>
    >>>>> Nate Hekman
    >>>>> Calgary, Alberta, Canada

    >
    Curt_C [MVP], Sep 23, 2004
    #9
  10. Nate Hekman

    Matt Berther Guest

    Hello Curt_C [MVP]" software_AT_darkfalz.com,

    I suppose I misunderstood... I thought you meant he needed to do something like this:

    private void Page_Load(object sender, EventArgs e)
    {
    if (Page.IsPostBack)
    {
    Button_Click(submitButton, EventArgs.Empty);
    }
    }

    which, of course, is completely wrong...

    --
    Matt Berther
    http://www.mattberther.com

    > I didn't specifically mean it could ONLY be from the load, just trying
    > to say that he needed to put in a catch in the load
    > sequence.....geesh....
    >
    > "Matt Berther" <> wrote in message
    > news:...
    >
    >> Hello Curt_C [MVP]" software_AT_darkfalz.com,
    >>
    >> Whoah... No you dont... The event needs to be hooked up and it will
    >> be executed somewhere between OnInit and OnLoad...
    >>
    >> --
    >> Matt Berther
    >> http://www.mattberther.com
    >>> of course not... you didn't call it. You'll have to do some
    >>> if(IsPostBack) in the load_page and call the function(s) that are
    >>> in the button_click
    >>>
    >>> "Nate Hekman" <> wrote in message
    >>> news:uDe$$...
    >>>
    >>>> It's single line. And it does reload the page--I can put a
    >>>> breakpoint in Page_Load and it breaks when I hit Enter, but it
    >>>> doesn't call btnSubmit_Click.
    >>>>
    >>>> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    >>>> news:%...
    >>>>
    >>>>> Is it single line or multiline? If it's multiline it's by design.
    >>>>> You can use clientside code to catch the ENTER press event and
    >>>>> call
    >>>>> the
    >>>>> button click.
    >>>>> --
    >>>>> Curt Christianson
    >>>>> Owner/Lead Developer, DF-Software
    >>>>> Site: http://www.Darkfalz.com
    >>>>> Blog: http://blog.Darkfalz.com
    >>>>> "Nate Hekman" <> wrote in
    >>>>> message
    >>>>> news:%...
    >>>>>> As I've mentioned a couple of times in the last few minutes(!),
    >>>>>> I've got a simple form with an edit box and a Submit button. If
    >>>>>> I type something in the Edit box and hit Enter I hear a click
    >>>>>> but nothing happens. If I click on the Submit button its Click
    >>>>>> event fires as I'd expect. If I click anywhere else on the web
    >>>>>> page and then hit Enter, the button's Click event fires too.
    >>>>>>
    >>>>>> I want the Click event to fire when the user is in the Edit box
    >>>>>> and hits Enter. How can I do this?
    >>>>>>
    >>>>>> Thanks for your help.
    >>>>>>
    >>>>>> Nate Hekman
    >>>>>> Calgary, Alberta, Canada
    Matt Berther, Sep 23, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MattB

    hitting "enter" on a page

    MattB, May 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    363
    MattB
    May 24, 2004
  2. Andy G

    Hitting the enter key

    Andy G, Dec 27, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,543
    Andy G
    Dec 28, 2004
  3. TS
    Replies:
    5
    Views:
    14,455
    Jeffrey Tan[MSFT]
    Nov 29, 2005
  4. Sunfire
    Replies:
    2
    Views:
    1,048
    Sunfire
    Nov 6, 2007
  5. HopfZ
    Replies:
    0
    Views:
    541
    HopfZ
    Aug 28, 2006
Loading...

Share This Page