Fire btnSubmit when user presses Enter on keyboard

Discussion in 'ASP .Net' started by =?Utf-8?B?amwzOTc3NQ==?=, Sep 23, 2004.

  1. I have a web form that I want to fire the Submit web control button when a
    user presses the Enter key on the keyboard. I added the following code in my
    Page_Load method and it works fine in a web form that contains the Submit web
    control button.

    Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit");

    However, if btnSubmit is in a usercontrol the code above no longer works.
    The framework changes the id for the button control to _ctl2_btnSubmit. Does
    anyone know how I can work around this problem? I could change the code to:

    Page.RegisterHiddenField("__EVENTTARGET", "_ctl2_btnSubmit");

    But, if I decide to add another control later I will have to change it again.

    Also, this should validate the form since the btnSubmit causevalidation is
    set to true.

    Please help.

    James
    =?Utf-8?B?amwzOTc3NQ==?=, Sep 23, 2004
    #1
    1. Advertising

  2. James,

    Why do you want to simulate a button click? Why can't you just submit the
    form with javascript submit() and pass parameters, if any, to the server via
    one of the standard ways of passing parameters?

    Eliyahu

    "jl39775" <> wrote in message
    news:...
    > I have a web form that I want to fire the Submit web control button when a
    > user presses the Enter key on the keyboard. I added the following code in

    my
    > Page_Load method and it works fine in a web form that contains the Submit

    web
    > control button.
    >
    > Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit");
    >
    > However, if btnSubmit is in a usercontrol the code above no longer works.
    > The framework changes the id for the button control to _ctl2_btnSubmit.

    Does
    > anyone know how I can work around this problem? I could change the code

    to:
    >
    > Page.RegisterHiddenField("__EVENTTARGET", "_ctl2_btnSubmit");
    >
    > But, if I decide to add another control later I will have to change it

    again.
    >
    > Also, this should validate the form since the btnSubmit causevalidation is
    > set to true.
    >
    > Please help.
    >
    > James
    >
    Eliyahu Goldin, Sep 23, 2004
    #2
    1. Advertising

  3. Dont you still have to capture the Enter key click event this way too?

    thx

    -BB


    "Eliyahu Goldin" <> wrote in message
    news:...
    > James,
    >
    > Why do you want to simulate a button click? Why can't you just submit the
    > form with javascript submit() and pass parameters, if any, to the server

    via
    > one of the standard ways of passing parameters?
    >
    > Eliyahu
    >
    > "jl39775" <> wrote in message
    > news:...
    > > I have a web form that I want to fire the Submit web control button when

    a
    > > user presses the Enter key on the keyboard. I added the following code

    in
    > my
    > > Page_Load method and it works fine in a web form that contains the

    Submit
    > web
    > > control button.
    > >
    > > Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit");
    > >
    > > However, if btnSubmit is in a usercontrol the code above no longer

    works.
    > > The framework changes the id for the button control to _ctl2_btnSubmit.

    > Does
    > > anyone know how I can work around this problem? I could change the code

    > to:
    > >
    > > Page.RegisterHiddenField("__EVENTTARGET", "_ctl2_btnSubmit");
    > >
    > > But, if I decide to add another control later I will have to change it

    > again.
    > >
    > > Also, this should validate the form since the btnSubmit causevalidation

    is
    > > set to true.
    > >
    > > Please help.
    > >
    > > James
    > >

    >
    >
    Brian Burgess, Nov 19, 2004
    #3
  4. =?Utf-8?B?amwzOTc3NQ==?=

    mortb Guest

    include a clinet javascript funciton something like:

    string postbackFunciton = @"function window.onkeypress()
    {
    if(event.keyCode = 13) " + Page.GetPostBackReference(yourControl , "") +
    "}";


    "Brian Burgess" <> wrote in message
    news:...
    > Dont you still have to capture the Enter key click event this way too?
    >
    > thx
    >
    > -BB
    >
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    >> James,
    >>
    >> Why do you want to simulate a button click? Why can't you just submit the
    >> form with javascript submit() and pass parameters, if any, to the server

    > via
    >> one of the standard ways of passing parameters?
    >>
    >> Eliyahu
    >>
    >> "jl39775" <> wrote in message
    >> news:...
    >> > I have a web form that I want to fire the Submit web control button
    >> > when

    > a
    >> > user presses the Enter key on the keyboard. I added the following code

    > in
    >> my
    >> > Page_Load method and it works fine in a web form that contains the

    > Submit
    >> web
    >> > control button.
    >> >
    >> > Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit");
    >> >
    >> > However, if btnSubmit is in a usercontrol the code above no longer

    > works.
    >> > The framework changes the id for the button control to _ctl2_btnSubmit.

    >> Does
    >> > anyone know how I can work around this problem? I could change the code

    >> to:
    >> >
    >> > Page.RegisterHiddenField("__EVENTTARGET", "_ctl2_btnSubmit");
    >> >
    >> > But, if I decide to add another control later I will have to change it

    >> again.
    >> >
    >> > Also, this should validate the form since the btnSubmit causevalidation

    > is
    >> > set to true.
    >> >
    >> > Please help.
    >> >
    >> > James
    >> >

    >>
    >>

    >
    >
    mortb, Nov 19, 2004
    #4
  5. ah yes .. that would work.. DOHH

    many thx

    -BB


    "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    news:...
    > include a clinet javascript funciton something like:
    >
    > string postbackFunciton = @"function window.onkeypress()
    > {
    > if(event.keyCode = 13) " + Page.GetPostBackReference(yourControl , "")

    +
    > "}";
    >
    >
    > "Brian Burgess" <> wrote in message
    > news:...
    > > Dont you still have to capture the Enter key click event this way too?
    > >
    > > thx
    > >
    > > -BB
    > >
    > >
    > > "Eliyahu Goldin" <> wrote in message
    > > news:...
    > >> James,
    > >>
    > >> Why do you want to simulate a button click? Why can't you just submit

    the
    > >> form with javascript submit() and pass parameters, if any, to the

    server
    > > via
    > >> one of the standard ways of passing parameters?
    > >>
    > >> Eliyahu
    > >>
    > >> "jl39775" <> wrote in message
    > >> news:...
    > >> > I have a web form that I want to fire the Submit web control button
    > >> > when

    > > a
    > >> > user presses the Enter key on the keyboard. I added the following

    code
    > > in
    > >> my
    > >> > Page_Load method and it works fine in a web form that contains the

    > > Submit
    > >> web
    > >> > control button.
    > >> >
    > >> > Page.RegisterHiddenField("__EVENTTARGET", "btnSubmit");
    > >> >
    > >> > However, if btnSubmit is in a usercontrol the code above no longer

    > > works.
    > >> > The framework changes the id for the button control to

    _ctl2_btnSubmit.
    > >> Does
    > >> > anyone know how I can work around this problem? I could change the

    code
    > >> to:
    > >> >
    > >> > Page.RegisterHiddenField("__EVENTTARGET", "_ctl2_btnSubmit");
    > >> >
    > >> > But, if I decide to add another control later I will have to change

    it
    > >> again.
    > >> >
    > >> > Also, this should validate the form since the btnSubmit

    causevalidation
    > > is
    > >> > set to true.
    > >> >
    > >> > Please help.
    > >> >
    > >> > James
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Brian Burgess, Nov 20, 2004
    #5
    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. =?Utf-8?B?d2FsZXNib3k=?=

    btnSubmit.click not firing when another control does postback

    =?Utf-8?B?d2FsZXNib3k=?=, Mar 23, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    838
    Steven Cheng[MSFT]
    Mar 30, 2005
  2. Moose
    Replies:
    6
    Views:
    15,287
    Alfonso Esteban Perdigón
    Aug 17, 2004
  3. BootNic
    Replies:
    11
    Views:
    920
    Jukka K. Korpela
    Aug 6, 2008
  4. HopfZ
    Replies:
    0
    Views:
    536
    HopfZ
    Aug 28, 2006
  5. jiayanxiang
    Replies:
    2
    Views:
    100
    Erwin Moller
    May 30, 2008
Loading...

Share This Page