Default Button Workaround for imagebuttons & linkbuttons, Part II

Okay...so, the post yesterday was clearly not as researched as it should have been. 

It's true...the Click() event does NOT work in FF...so, the solution I had to utilize the click event had a rather short lifespan. 

I tried to dynamically add the __onPostBack javascript event onKeyPress as well as onkeydown - to no avail.  I'm not sure why it wouldn't work...but, it just wouldn't.  (I'm using an image button, .NET 3.5, a lot of JS & AJAX on the page - not sure what, if any of that muddies the waters)

So...I decided to stick with my core solution, and just find a workaround for the lack of a click() FF event. 

I added this to my page..

function FireClick(id){

if ($get(id).dispatchEvent){

var e = document.createEvent("MouseEvents");

e.initEvent("click", true, true);

$get(id).dispatchEvent(e);

}

else

{

$get(id).click();

}

}


Then, I used this...

tbSearchBox.Attributes.Add("onkeydown", "javascript:if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){FireClick('" _

& btnSearchButton.ClientID & "');return false;}else return true;")

Nothing too special - Basically I'm firing my FireClick() JS event to handle the click() - but seems to work on IE6/7 and FF....

Print | posted on Friday, August 01, 2008 11:56 AM

Feedback

No comments posted yet.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 5 and 7 and type the answer here: