Link to home
Start Free TrialLog in
Avatar of adwooley2
adwooley2

asked on

Setting ImageButton as DefaultButton ASP.NET 2.0

Hello.  I hope there is a more definitive answer than what I've been reading.  I have an imagebutton on an ASP.NET form that I want to set as the default button (when the user presses ENTER).  Does anybody have a solution for this?
Avatar of lijunguo
lijunguo
Flag of Australia image

Avatar of adwooley2
adwooley2

ASKER

That didn't work for me.  What I did was I added Implements iButtonControl on the image button and voila!
Thanks anyway.
<form id="form1" runat="server" defaultbutton="ImageButton1">

Can this work for you?
No, can't use that, since I am using a master page in my environment.  Thanks anyway.
In that case, you can do that in code behind

this.Form.DefaultButton = "ImageButton1";
Have you ever tested that? Image buttons cannot be set as the default button alone.  They don't support IButtonControl.  That is why I  added Implements iButtonControl on the image button and then set it as the DefaultButton.  In other words, I've already solved this issue.
ASKER CERTIFIED SOLUTION
Avatar of Edwin_C
Edwin_C
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Really!?  It didn't work for me, and from everything that I was reading on the web, you're not supposed to be able to do what you did.  What version of Visual Studio are you using?
I am using VS2005 and ASP.NET 2.0.

After consulting the reference material, you are correct in the way that DefaultButton must implement IButtonControl but ImageButton does implement IButtonControl.

To further clarify things, as of ASP.NET 2.0 you can set the DefaultButton property on the form object or on a panel object.  So, for the example given in this thread, if you are in a masterpage/child page situation with the form being on the masterpage, you could create a panel object on your child page and set the default button on that panel.  That way you do not need to modify the masterpage's form object in any way.
If you have multiple default buttons set (due to multiple panels), when the page postback is processed, the default will be determined by the context of the currently selected control.
for further details see:  http://weblogs.asp.net/scottgu/archive/2005/08/04/421647.aspx