ASP.NET 母版页 DefaultButton 覆盖

发布于 2024-09-16 10:56:07 字数 552 浏览 3 评论 0原文

我有一个带有表单元素的母版页,并将 defaultbutton 属性设置为服务器端 ImageButton。在我的其中一个页面上,我想通过在 Page_Load 事件中设置 Forms DefaultButton 来“覆盖”母版页默认按钮属性。

IE 在母版页上:

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

在“覆盖”母版页属性的页面 Page_Load 事件上:

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

出现错误:

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

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

我可能做错了什么或解决问题的不同方法有什么想法吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

翻了热茶 2024-09-23 10:56:07

使用唯一 ID。由于您可以拥有多个具有相同服务器 id 的服务器控件(即在 GridView 中),因此框架需要唯一的 id 来匹配。

this.Form.DefaultButton = this.ibRecalc.UniqueID;

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;
猫瑾少女 2024-09-23 10:56:07

您可以尝试使用面板的“DefaultButton”属性...

将按钮或整个页面或 div 放入 asp:Panel

// 启动面板

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

。 ......

//根据您的要求进行控制

.........

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

关闭面板

不需要覆盖母版页按钮

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

也只是曾经 2024-09-23 10:56:07

如果您将面板移至登录模板内:-

<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>

那么它将无需代码即可工作。
您可以根据您的要求设置loginbuttontype="Image"或链接或按钮。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文