Default Button Workaround for imagebuttons & linkbuttons

UPDATE: If you're looking for the solution that will work in FireFox & IE...Go here

Okay, I admit, this is yet another post so I know where to go in 3 months when I totally forget this day. 

Long story short: I was trying to use the DefaultButton property on a panel in order to get a button clicked by default when a user hits enter on my search form.  I was using an ImageButton, and surprise! That won't freakin' work!  Seriously...try it. 

I came across a post on here ( http://bytes.com/forum/thread288545.html ) from S. Justin Gengo. With a link to his site.... http://www.aboutfortunate.com/Code-Repository.aspx?entryid=14

And booya, his simple JS code works perfectly in IE6/7 & FF. 

Good day, sir.

ps - Thank you Justin

___
 tbSearchBox.Attributes.Add("onkeydown", _
    "javascript:if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){document.getElementById('" _
    & btnSearchButton.ClientID & "').click();return false;}else return true;")

Print | posted @ Thursday, July 31, 2008 3:08 PM

Comments on this entry:

Gravatar # re: Default Button Workaround for imagebuttons & linkbuttons
by anon at 7/31/2008 6:34 PM

I could be off here, but I thought .click() wasnt supported in firefox http://www.google.com/search?hl=en&q=.click+javascript+firefox
Gravatar # re: Default Button Workaround for imagebuttons & linkbuttons
by anon at 7/31/2008 6:46 PM

You could use __doPostBack("' & btnSearchButton.UniqueID & '", '') instead however, if you're doing client-side validation you'd want to call that function first.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 
Twitter