5

The problem I'm trying to solve:

I have several text boxes in an asp:Panel. When the user hits Enter from any of those boxes, I want the form to submit as if they've clicked btnAddTag. (When the cursor is not in those boxes, I have a different default submit button.)

The aspx:

<asp:Panel id="thePanel" runat="server">
    <asp:Button ID="btnAddTag" Text="Add Tag" runat="server" />
</asp:Panel>

The vb:

tagPanel.DefaultButton = btnAddTag.UniqueID

The exception:

The DefaultButton of 'tagPanel' must be the ID of a control of type IButtonControl.

The value of btnAddTag.UniqueID is ctl00$phMain$btnAddTag (there's a master page, this section is called phMain).

I've also tried CType(tagPanel.FindControl("btnAddTag"), Button).UniqueID.

egrunin
  • 24,650
  • 8
  • 50
  • 93

2 Answers2

3

do:

tagPanel.DefaultButton = btnAddTag.ID

more info here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx

Victor
  • 4,721
  • 1
  • 26
  • 31
  • That worked! Although I have no idea why, everywhere else I seem to need UniqueID... – egrunin Jan 31 '11 at 18:54
  • You must use a relative "path". Meaning, use a string similar to the UniqueID so that it provides a path from the container down to the child control. I've never seen this documented anywhere other than in Q/A posts. http://connect.microsoft.com/VisualStudio/feedback/details/103530/defaultbutton-in-panel-for-wizard-errs – Darren Griffith Feb 08 '13 at 00:09
0

You should set the control's ID not UniqueID:

tagPanel.DefaultButton = btnAddTag.ID

kolbasov
  • 1,548
  • 11
  • 15