Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Panels and Text Boxes submit twice on 'Enter'?

Status
Not open for further replies.

kcyxa

Programmer
Feb 28, 2007
6
CA
Hi,

Why is it that ASP.NET panels and text boxes submit twice on enter, while dropdown lists don't?

I have a panel with contols mentioned above and a javascript attached to the panel, designed to execute an imagebutton event when a user presses 'Enter'.

If a user presses enter while the focus is on the dropdown list, Page_Load event is executed, and then the imgButton_Click event. If the focus is on a text box or on the panel, then the Page_Load event is executed AGAIN after the imgButton_Click event is done.

How can I stop the second Page_Load event from executing?

Thanks,

Ks.
 
I got it.
Had to add a couple of lines to my JS script:
event.returnValue=false;
event.cancel = true;

function doClick(buttonName,e)
{
var key;
if (window.event) key = window.event.keyCode;
else key = e.which;

if (key == 13)
{
var btn = document.getElementById(buttonName);
if (btn != null)
{
event.returnValue=false;
event.cancel = true;

btn.click();
}
}
else
{
return true;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top