将 MasterPage ImageButton 事件传递给内容页面
我在 MasterPage 中有 ImageButton。我希望触发 OnClick 事件并由 MasterPage 内托管的 .ASPX 页面捕获?
母版页:
<asp:ImageButton ID="btnClear" OnClick="Clear_Click"
ImageUrl="images/Back_Icon_06.png" runat="server" AlternateText="Clear"
width="38" height="39"/>
I have ImageButton in a MasterPage. I want the OnClick event to fire and be captured by the .ASPX page hosted inside the MasterPage?
MasterPage:
<asp:ImageButton ID="btnClear" OnClick="Clear_Click"
ImageUrl="images/Back_Icon_06.png" runat="server" AlternateText="Clear"
width="38" height="39"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
母版页实际上是页面的子级(事实上,它是一个 UserControl)。我们不希望页面必须了解其子控件的私密细节(这就是为什么我们首先将这些方面委托给这些控件),因此正确的方法是处理主控件上的单击事件页面并从那里触发该页面处理的母版页上的另一个事件:
Master:
Page:
The masterpage is actually a child of the page (in fact, it's a UserControl). We don't want the page to have to be aware of the intimate details of its child controls (thats why we delegate those aspects to those controls in the first place), so the correct approach would be to handle the click event on the master page and from there fire another event on the masterpage which the page handles:
Master:
Page:
我建议在内容页面中指定强类型母版页,并在母版页端公开事件
这是一个很好的MSDN 参考
这类似于 Rex M 指定的内容,但只是稍微简化了对母版页的访问。
I would recommend specifying a strongly typed master page in your content page and exposing the event on the master page side
Here's a good MSDN reference
This is similar to what Rex M specified but just simplifies accessing the Master Page a little bit.