ASP.NET主页DefaultButton覆盖

Die*_*r G 19 c# asp.net defaultbutton imagebutton

我有一个带有表单元素的主页面,defaultbutton属性设置为服务器端的ImageButton.在我的一个页面上,我想通过在Page_Load事件中设置Forms DefaultButton来"覆盖"masterpage defaultbutton属性.

即在主页上:

<form id="form1" runat="server" defaultbutton="btnSearch">....</from>
Run Code Online (Sandbox Code Playgroud)

在"覆盖"主页面属性的页面Page_Load事件上:

this.Form.DefaultButton = this.ibRecalc.ID;
Run Code Online (Sandbox Code Playgroud)

它错误:

'form1'的DefaultButton必须是IButtonControl类型的控件的ID

我正在使用实现IButtonControl的图像按钮

我可能做错了什么或以不同方式解决问题的任何想法?

谢谢

Reb*_*off 44

使用UniqueId.由于您可以拥有多个具有相同服务器标识的服务器控件,即在GridView中,框架需要唯一的id才能匹配.

this.Form.DefaultButton = this.ibRecalc.UniqueID;
Run Code Online (Sandbox Code Playgroud)