Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Fire btnSubmit when user presses Enter on keyboard

Reply
Thread Tools

Fire btnSubmit when user presses Enter on keyboard

 
 
=?Utf-8?B?amwzOTc3NQ==?=
Guest
Posts: n/a
 
      09-23-2004
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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      09-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Brian Burgess
Guest
Posts: n/a
 
      11-19-2004
Dont you still have to capture the Enter key click event this way too?

thx

-BB


"Eliyahu Goldin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >

>
>



 
Reply With Quote
 
mortb
Guest
Posts: n/a
 
      11-19-2004
include a clinet javascript funciton something like:

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


"Brian Burgess" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dont you still have to capture the Enter key click event this way too?
>
> thx
>
> -BB
>
>
> "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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
>> >

>>
>>

>
>



 
Reply With Quote
 
Brian Burgess
Guest
Posts: n/a
 
      11-20-2004
ah yes .. that would work.. DOHH

many thx

-BB


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

+
> "}";
>
>
> "Brian Burgess" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Dont you still have to capture the Enter key click event this way too?
> >
> > thx
> >
> > -BB
> >
> >
> > "Eliyahu Goldin" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > 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
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Altering default submit button when user presses Enter BootNic HTML 11 08-06-2008 07:06 PM
Turn of the "Ding" sound when user presses enter jiayanxiang Javascript 2 05-30-2008 01:14 PM
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
btnSubmit.click not firing when another control does postback =?Utf-8?B?d2FsZXNib3k=?= ASP .Net 8 03-30-2005 04:22 AM
Can you perform 2 functions when a user presses [submit] on a form? Moose HTML 6 08-17-2004 06:08 PM



Advertisments