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

D

David Lozzi

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
 
D

David Lozzi

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
net> wrote in message news:%23O5JCmC%[email protected]...
 
K

Karl Seguin [MVP]

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 said:
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
net> wrote in message news:%23O5JCmC%[email protected]...
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top