user enter key to control my login form

G

Grant Merwitz

Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button, but
this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLogIn'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 
K

Kevin Spencer

The document reloads because it has posted back.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
G

Grant Merwitz

ok, but can i have a solution to my problem

Kevin Spencer said:
The document reloads because it has posted back.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

Grant Merwitz said:
Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button,
but this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password
textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLogIn'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 
J

Jeff Sheldon

Grant,

I've run into this bug before. Place a hidden html textbox somewhere in
the form.

<INPUT type="text" style="DISPLAY:none">

Then when you hit enter in the login field it should fire the login button's
click event.

-Jeff


Grant Merwitz said:
ok, but can i have a solution to my problem

Kevin Spencer said:
The document reloads because it has posted back.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

Grant Merwitz said:
Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button,
but this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password
textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLogIn'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 
K

Kevin Spencer

From what I've read so far, you don't HAVE a problem. The ENTER key is
submitting the form. Of course, you don't need all that code to do it. The
ENTER key submits the form by default. The problem you stated was that you
wanted the ENTER key to submit the form.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

Grant Merwitz said:
ok, but can i have a solution to my problem

Kevin Spencer said:
The document reloads because it has posted back.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

Grant Merwitz said:
Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button,
but this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password
textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLogIn'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 
M

Michael

I'm assuming you want to validate the user on an enter keypress and redirect
to an appropriate page based on the results. There is a difference between
submit in asp.net and submit in asp. It's a good idea to understand the
differences...

Anyway, put this jscript in the html:
<script language="javascript">
function fnTrapKD(btn){
if (document.all) {
if (event.keyCode == 13) {
event.returnValue=false;
event.cancel = true;
btn.click();}}}
</script>

And plug this into Page_Load:
txPassword.Attributes.Add("onkeydown", "fnTrapKD(document.all." &
cmLogin.ClientID & ")")

Hope this helps..
 
J

Jeff Sheldon

Michael,

Wouldn't that only work in Internet Explorer?

-Jeff

Michael said:
I'm assuming you want to validate the user on an enter keypress and
redirect
to an appropriate page based on the results. There is a difference between
submit in asp.net and submit in asp. It's a good idea to understand the
differences...

Anyway, put this jscript in the html:
<script language="javascript">
function fnTrapKD(btn){
if (document.all) {
if (event.keyCode == 13) {
event.returnValue=false;
event.cancel = true;
btn.click();}}}
</script>

And plug this into Page_Load:
txPassword.Attributes.Add("onkeydown", "fnTrapKD(document.all." &
cmLogin.ClientID & ")")

Hope this helps..

Grant Merwitz said:
Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button, but
this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password
textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLog
In'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button
1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 
M

Michael

Yes.

Jeff Sheldon said:
Michael,

Wouldn't that only work in Internet Explorer?

-Jeff

Michael said:
I'm assuming you want to validate the user on an enter keypress and
redirect
to an appropriate page based on the results. There is a difference between
submit in asp.net and submit in asp. It's a good idea to understand the
differences...

Anyway, put this jscript in the html:
<script language="javascript">
function fnTrapKD(btn){
if (document.all) {
if (event.keyCode == 13) {
event.returnValue=false;
event.cancel = true;
btn.click();}}}
</script>

And plug this into Page_Load:
txPassword.Attributes.Add("onkeydown", "fnTrapKD(document.all." &
cmLogin.ClientID & ")")

Hope this helps..

Grant Merwitz said:
Hi

I am trying to get the enter key to submit my login form
The login form is currently in a control on the page and uses an
asp:imagebutton as it's login button.

If a user presses enter currently, the page just reloads.
I have tried to use some javascript to set the enter key on the button, but
this script only seems to work for an asp:button and not the
asp:imagebutton.
Any help on how to do this would be greatly appreciated.

The javascript i am using currently is: (attached to the password
textbox)
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:imgLog
In'].click();return
false;} else return true; "
- This still refreshes the page when enter is click i.e. its not working

When i place a asp:button on the page that calls the same method as the
asp:imagebutton, this works fine
onkeydown="if (event.keyCode && event.keyCode == 13)
{document.Form1.elements['Header1:AuthControl_Main1:AuthControl_Login:Button
1'].click();return
false;} else return true; "

HELP!!

TIA

Grant
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top