...

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



earni23
09-14-2010, 08:43 PM
Hi!
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)
{
document.getElementById(obj).click();
return false;
}
else
return true;
}


codebehind:



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

Mike_O
09-14-2010, 09: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:

changelang.Focus();

Regards,
Mike



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum