开发者

Setting DefaultButton to button.UniqueID throws exception

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$phM开发者_如何学编程ain$btnAddTag (there's a master page, this section is called phMain).

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


do:

tagPanel.DefaultButton = btnAddTag.ID

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


You should set the control's ID not UniqueID:

tagPanel.DefaultButton = btnAddTag.ID

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜