Fire btnSubmit when user presses Enter on keyboard

G

Guest

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
 
E

Eliyahu Goldin

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
 
B

Brian Burgess

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

thx

-BB
 
M

mortb

include a clinet javascript funciton something like:

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

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top