ASP.NET Master page DefaultButton override
Asked Answered
P

3

19

I have a master page with a form element and the defaultbutton attribute set to a server-side ImageButton. On one of my pages I want to "override" the masterpage defaultbutton attribute by setting the Forms DefaultButton in the Page_Load event.

i.e On mater page:

<form id="form1" runat="server" defaultbutton="btnSearch">....</from>

On the page Page_Load event that "override" the master page attribute:

this.Form.DefaultButton = this.ibRecalc.ID;

It errors with :

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

I am using image buttons which implements IButtonControl

Any ideas of what I might be doing wrong or a different way to approach the problem?

Thanks

Precess answered 1/9, 2010 at 3:19 Comment(2)
What type is ibRecalc? Does it implement the specified interface?Baptiste
@Tahbaza: ibRecalc is a ASP.NET ImageButton control i.e it does implement IButtonControlPrecess
C
46

Use UniqueId. Since you can have multiple server controls with the same server id, ie, in a GridView, the framework needs to the unique id to match up to.

this.Form.DefaultButton = this.ibRecalc.UniqueID;
Cerium answered 1/9, 2010 at 3:26 Comment(0)
K
2

You could try using the "DefaultButton" property of a Panel...

Place your button or whole page or div in asp:Panel

// start panel

asp:Panel ID="pnlOpsCallSummay" runat="server" DefaultButton="btnSearch"

............

//Controls of your requirement

..........

asp:Button ID="btnSearch" runat="server" Text="Search"

close the pannel

No need of Overriding the master page button

Kleptomania answered 11/12, 2014 at 7:15 Comment(1)
This is interesting, you will be able to have default buttons for multiple panels within one page then. Nice.Greatgrandaunt
S
0

If you move the panel inside the login's template:-

<asp:login id="Login2" runat="server" loginbuttontype="Image">
<layouttemplate>
   <asp:`enter code here`panel id="Panel1"   runat="\
     server"defaultbutton="LoginImageButton">
   </asp:Panel>
 </LayoutTemplate>
</asp:Login>

Then it will work without code. You can set loginbuttontype="Image" or Link or button according to your requirement.

Syllabub answered 2/9, 2016 at 7:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.