.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe
  • Home
  • About Me
  • Advertising
  • Click Here to Ask a question
    • Privacy Policy
  • Site Map

Panel DefaultButton does not work

September 23, 2008 By: Dave

misc_vol2_051 Or, at least, it didn’t. Here’s what happened:

Yesterday a client asked me to help track down a problem he was having with setting the default button for a text box.

As you should already know, you can make ASP.NET automatically click a specific button on the page (Button, ImageButton, or LinkButton) by grouping everything in a Panel and setting the DefaultButton property to the ID of the button you want to have automatically clicked.

Of course, in situations like these, you can pull your hair out trying to find the problem. There was nothing obviously wrong with the code. Everything was grouped into a panel. All of the Panels had their DefaultButton properties set to the correct button.

Maybe it’s because it is an ImageButton? No, not only are ImageButtons supported, but creating a quick demo verified that they did in fact work.

But what’s this? When I put the ASCX file into design view, it does not render the panel with more than a 1px high rectangle. That’s odd… wonder why it’s doing that. Let’s try resizing it. Nope. That doesn’t work.

And then I looked closer.

All of the code basically looked something like this:

<tr>
  <asp:Panel DefaultButton="m_ibKeyIngredient"
      ID="m_pKeyIngredient"
      runat="server" Width="370px">
    <td valign="top">
      <asp:TextBox ID="m_tbKeyIngredient"
        runat="server"
        Width="244px"></asp:TextBox>
      <asp:ImageButton ID="m_ibKeyIngredient"
        runat="server"
        OnClick="m_ibKeyIngredient_Click"
        ImageUrl="images/gobutton.gif"
        ImageAlign="AbsBottom" />
    </td>
  </asp:Panel>
</tr>

If you casually read over this code, you completely miss the fact that the TD elements are INSIDE of the Panel. You see the TR element and the panel and if you aren’t thinking clearly, you think the TR element is the cell when in fact, it is the row. The TD elements that represent the cell are further in and easy to miss.

You need to keep in mind that the Panel renders itself as a DIV and you can’t have a DIV tag inside a TR tag.

It turns out that swapping the Panel tag with the TD element solved the whole problem. Unfortunately, this took us several hours of frustration to figure out.

So, what did we learn?

  1. If your ASP.NET client side code isn’t working as you’d expect, validate your HTML.
  2. When working on a problem, if you see another problem that is part of the same code, it is not always inappropriate to take a detour to try to fix that problem. It may in fact fix the problem you are working on. If nothing else, it will give your mind a break.

 

Other post in Did you know
  • Did you know - Zip is built into .NET? - August 21st, 2008
  • Panel DefaultButton does not work - September 23rd, 2008
  • Automatic Implementation of Interfaces - October 1st, 2008
  • Easily Find Classes, Methods, and Variables - November 17th, 2008
  • Advantages of Using Class Diagram - November 20th, 2008
  • Renaming Properties, Methods and Variables - November 25th, 2008
  • Finding a CSS Class Definition - December 3rd, 2008

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related Post

  • jQuery – Date Picker
  • jQuery Dialog – With Validation Controls
  • Structure of my ASP.NET Web Applications
Bookmark to:

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone Add to Facebook Add to Slashdot Add to Stumble Upon Add to Technorati
Hide Sites
Tags: asp.net, Button, DefaultButton, ImageButton, LinkButton, Panel

Comments are closed.

← DotNetNuke Modules – Module Settings
DotNetNuke Modules – Retrieving Settings →
  • Search

  • Subscribe

    U COMMENT
    I FOLLOW

    Subscribe in a reader

    OR

    Subscribe via e-mail

    Enter your email address: 

    Delivered by FeedBurner

     

  • Follow Me

    • Twitter
    • FaceBook
    • Digg
    • StumbleUpon
    • Propeller
    • Delicious
    • Plaxo

     

  • Recent Posts

    • ASUS Eee PC 1005HA-PU1X-BK Black Netbook
    • jQuery – Date Picker
    • Using VB.NET From CSharp
    • iTextSharp – Adding Images
    • Hungarian Notation – Use What Works, Spit Out The Bones
    • Pre Order Windows 7
    • jQuery Dialog – With Validation Controls
    • iTextSharp – The easy way
    • Structure of my ASP.NET Web Applications
    • 35% Off Accronis True Image 2009 Home
    • VB.NET Hide Module Name
    • ASP.NET/VB.NET – Video Training
    • Does jQuery Make Us Lazy?
    • PDFs Using iTextSharp
    • Programming SEO – Ping



  • Advertise on this site through Lake Quincy Media
  • DotNetNuke Sponsor

     

    Most Valuable Blogger
  • Sponsor

  • Categories

    • Advanced CSharp
    • Advanced VB.NET
    • ASP.NET MVC
    • Did you know
    • DotNetNuke – Module Development
    • DotNetNuke – Skinning
    • internationalization
    • iTextSharp
    • jQuery
    • none
    • Seach Engine Optimization
    • Silverlight
    • SQL For Programmers
    • Twitter
    • winforms
  • Cloud

    .net ajax architecture asp.net book books containers csharp css dal dataset datasets dotnetnuke events gridview images internationalization internet explorer javascript jQuery json linq listview modules ms-sql MVC objectdatasource programming reflection seo Silverlight skinning sql testing tsql tutorial Twitter twitterizer vb.net video view Vista visual studio webservice WordPress
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    • Privacy Policy
  • Calendar

    September 2008
    S M T W T F S
    « Aug   Oct »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • Blogroll

    • Alvin Ashcraft’s Morning Dew
    • ASP.NET Consulting
    • Life Hacker
    • Remember Anything
    • The Price of Their Toys
    • Uncategorized Thought


.NET Answers © 2007 - 2008 All Rights Reserved.
Entries and Comments.