If you’re having trouble setting the default button in an ASP.NET Panel that has a Master Page…

Posted: August 28, 2011 in Uncategorized

I struggled with this for about a day, and there were a lot of sites saying I should just use button.ID or button.UniqueID to set the default button for a panel. Nope, that wasn’t working. Some users were complaining the issue was only occurring on setting default button when in a control contained in a Master page.

The error would be:

The DefaultButton of panel  or page must be the ID of a control of type IButtonControl.

So, here’s what you do to fix it:

// Set the default buttons.

((Panel)Page.FindControl(nameofthepanel.UniqueID)).DefaultButton = nameofthebutton.ID;


I hope that helps Smile

Best,

-Auri

Comments
  1. Ali says:

    same issue :-/

  2. Suzy says:

    I have the same issue, I use :
    pnlDetails.DefaultButton = btnCalculate.UniqueID;

    and this works fine in my development environment but when I put it live I get the above error saying ‘The DefaultButton of panel or page must be the ID of a control of type IButtonControl.’

    The button is in another panel and in another contentplaceholder

    Any idea’s?

    Kind regard Suzy

    • Auri says:

      Are you sure your latest code, and ONLY your latest code, has been deployed? Make sure they didn’t simply copy over new files.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s