By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,631 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,631 IT Pros & Developers. It's quick & easy.

Press enter fire specific button in form in ASP.Net 2

P: n/a
Howdy,

I'm using asp.net 2.0 and am trying to get one text box on the page, after
the user presses enter, to "click" a specific button. I copied the
javascript I used for a .net 1.1 web app I did a while ago but it doesn't
appear to work with .net 2.0? Below is my script. Any ideas?

<script language="javascript">

function clickButton(e, buttonid){

var bt = document.getElementById(buttonid);

if (typeof bt == 'object'){

if(navigator.appName.indexOf("Netscape")>(-1)){

if (e.keyCode == 13){

bt.click();

return false;

}

}

if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){

if (event.keyCode == 13){

bt.click();

return false;

}

}

}

}

</script>

in the textbox

onkeydown="javascript: return
clickButton(event,'_ctl0_uscTopBag_btnSearch');"

The event fires to the line of bt.click() but it doesn't appear to click it.
The ID for the button I am sending is what the ID of the button is after the
page renders, which javascript likes. Any ideas?

Thanks!!

David Lozzi
Oct 25 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
in asp.net 2.0, panel's have a defaultButton property which does what you
want.

You can see an example at:
http://weblogs.asp.net/scottgu/archi...04/421647.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Howdy,

I'm using asp.net 2.0 and am trying to get one text box on the page, after
the user presses enter, to "click" a specific button. I copied the
javascript I used for a .net 1.1 web app I did a while ago but it doesn't
appear to work with .net 2.0? Below is my script. Any ideas?

<script language="javascript">

function clickButton(e, buttonid){

var bt = document.getElementById(buttonid);

if (typeof bt == 'object'){

if(navigator.appName.indexOf("Netscape")>(-1)){

if (e.keyCode == 13){

bt.click();

return false;

}

}

if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){

if (event.keyCode == 13){

bt.click();

return false;

}

}

}

}

</script>

in the textbox

onkeydown="javascript: return
clickButton(event,'_ctl0_uscTopBag_btnSearch');"

The event fires to the line of bt.click() but it doesn't appear to click
it. The ID for the button I am sending is what the ID of the button is
after the page renders, which javascript likes. Any ideas?

Thanks!!

David Lozzi


Oct 25 '06 #2

P: n/a
But I have only one Form for the page and two or three submit buttons, for
example

Top of page is search site textbox with a button
Middle of page is signup for new account, multiple fields and a submit
button
Right of page is a login box with username and password with a submit
button.

The signup for new account is fired when enter is pressed in any of the
sections, which makes sense. How do I specify where to submit to?

Thanks

David Lozzi
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
in asp.net 2.0, panel's have a defaultButton property which does what you
want.

You can see an example at:
http://weblogs.asp.net/scottgu/archi...04/421647.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>Howdy,

I'm using asp.net 2.0 and am trying to get one text box on the page,
after the user presses enter, to "click" a specific button. I copied the
javascript I used for a .net 1.1 web app I did a while ago but it doesn't
appear to work with .net 2.0? Below is my script. Any ideas?

<script language="javascript">

function clickButton(e, buttonid){

var bt = document.getElementById(buttonid);

if (typeof bt == 'object'){

if(navigator.appName.indexOf("Netscape")>(-1)){

if (e.keyCode == 13){

bt.click();

return false;

}

}

if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){

if (event.keyCode == 13){

bt.click();

return false;

}

}

}

}

</script>

in the textbox

onkeydown="javascript: return
clickButton(event,'_ctl0_uscTopBag_btnSearch'); "

The event fires to the line of bt.click() but it doesn't appear to click
it. The ID for the button I am sending is what the ID of the button is
after the page renders, which javascript likes. Any ideas?

Thanks!!

David Lozzi



Oct 25 '06 #3

P: n/a
wrap the textboxes in a <asp:panel and specify it's defaultButton.

I think you are thinking about the defaultButton for the form...but you can
specify it at the panel level...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"David Lozzi" <dl****@nospam.nospamwrote in message
news:ui****************@TK2MSFTNGP04.phx.gbl...
But I have only one Form for the page and two or three submit buttons, for
example

Top of page is search site textbox with a button
Middle of page is signup for new account, multiple fields and a submit
button
Right of page is a login box with username and password with a submit
button.

The signup for new account is fired when enter is pressed in any of the
sections, which makes sense. How do I specify where to submit to?

Thanks

David Lozzi
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%2******************@TK2MSFTNGP02.phx.gbl...
>in asp.net 2.0, panel's have a defaultButton property which does what you
want.

You can see an example at:
http://weblogs.asp.net/scottgu/archi...04/421647.aspx

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"David Lozzi" <dl****@nospam.nospamwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
>>Howdy,

I'm using asp.net 2.0 and am trying to get one text box on the page,
after the user presses enter, to "click" a specific button. I copied the
javascript I used for a .net 1.1 web app I did a while ago but it
doesn't appear to work with .net 2.0? Below is my script. Any ideas?

<script language="javascript">

function clickButton(e, buttonid){

var bt = document.getElementById(buttonid);

if (typeof bt == 'object'){

if(navigator.appName.indexOf("Netscape")>(-1)){

if (e.keyCode == 13){

bt.click();

return false;

}

}

if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){

if (event.keyCode == 13){

bt.click();

return false;

}

}

}

}

</script>

in the textbox

onkeydown="javascript: return
clickButton(event,'_ctl0_uscTopBag_btnSearch') ;"

The event fires to the line of bt.click() but it doesn't appear to click
it. The ID for the button I am sending is what the ID of the button is
after the page renders, which javascript likes. Any ideas?

Thanks!!

David Lozzi




Oct 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.