View Full Version : ASP.NET calls the first declared asp-controlīs onclick when javascript is disabled

09-14-2010, 07:43 PM
When I press enter in the asp-textbox, the first declared asp-controlīs onclick is fired when javascript is disabled. Why is that?

I have two imagebuttons (ids: "changelang" and "search") which both have a onclick-event. The imagebutton with the id "changelang" is appearing first on the website and itīs onclick-event is therefore fired when pressing enter in the textbox (id: tb) when javascript is disabled. How do I change, so a specific id is fired?

function SearchClick(obj)
if (window.event.keyCode == 13)
return false;
return true;


tb.Attributes.Add("onkeypress", "return SearchClick('" + search.ClientID + "');");

09-14-2010, 08:18 PM
Hey earni23,

Two things:

#1. The OnClick event is server-side. There is however an OnClientClick event available on some of the server-side controls (past framework 2.0, I think). Sure you're not mixing those up?

#2. Regarding your two imagebutton controls, this has to do with setting the focus on whatever control you want. You can do this either via server or client-side. I suppose you will want to do it via server-side, so just put the following inside your Page_Load method:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum