如何绑定 ASP.NET 母版页和内容页中的特定事件处理程序
在母版页中,页面顶部有一个容器,其中应包含特定于内容页面的按钮。在内容页面中,我有“创建”、“修改”等按钮...... 母版页中的容器应始终位于顶部,但按钮最终会随着内容的不同而变化。关于如何将内容页功能绑定到母版页之一的任何想法? 目前,我在母版页中有一个面板,在运行时,我附加了内容页面中的按钮,但事件处理程序未附加,并且仅呈现页面重新加载。为什么会发生这种情况?
感谢您的帮助!
布兰科
In the master page I have a container on top of the page, which should hold buttons specific to the content page. In a content page, I have buttons like "Create", "Modify", etc...
The container in the master page should always be on top, but the buttons will eventually change with different content. Any idea on how I can bind content page functionality to the one of the master page?
Currently I have a panel in the master page and during run time, I attach the button from the content page, but the event handler is not attached and renders only a page reload. Why is that happening?
Thanks for the help!
Branko
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这样的技术:您的控件实现 IProducer 接口,您的母版页实现 IConsumer 接口。
IProducer将生成事件(命令)。消费者将处理这些事件。
我正在使用具有命令名称(创建、修改...)和参数(字符串)的事件。消费者将处理这些命令并更新视图(也使用模型视图演示者模式)。
控件也可以实现 IView。例如,我有一段代码可以执行 ASP.NET MVC 执行的操作。 IView 生成事件,Presenter 处理它们,对 Model(业务层或数据层)执行某些操作并更新视图。
运气。
Use so technic: you controls implements IProducer interface and your Master page implements IConsumer interface.
IProducer will generate events (commands). Consumer will handle these events.
I am using event that has command name (Create, Modify...) and arguments (string). Consumer will process these commands and update view (use Model View Presenter pattern also).
Controls can implement IView also. For example, I have a code that does something the ASP.NET MVC does. IView gererates events, Presenter handles them, does something with Model (business layer, or data layer) and updates the view.
Luck.
最简单的方法(但不是最灵活)是在顶部面板内向母版页添加一个新的内容占位符,并为每个页面提供所需的按钮以及任何脚本和/代码隐藏作为该位置的内容持有者。当然,这会使混合特定于页面的按钮和通用按钮变得稍微困难,但在大多数情况下,无论如何都不需要这样做,因为特定于页面的控件被分组在一起。
The easiest way (but not the most flexible) would be to add to your master page a new content placeholder inside the top panel and for each page to provide the buttons it needs along with any scripts and/code behind as a content for that place holder. Of course, that would make it slightly harder to mix page-specific buttons and common ones, but in most scenarios that's not needed anyway as the page-specific controls are grouped together.