如何处理内容页中的母版页按钮事件?
我的问题是我有一个动态创建内容的基页。我的母版页上有一些按钮可以触发我的基本页需要了解的事件。但是我的基页上的 OnLoad 函数在母版页上的 Button_Command 函数之前触发。因此,我要么需要找到一种方法在 Button_Command 函数有机会设置变量后加载我的基本页面,要么我必须从 Button_Command 函数调用基本页面中的函数。
My problem is this I have a base page that creates content dynamically. There are buttons on my Master Page that fire events that my base page needs to know about. But the OnLoad function on my base page fires before my Button_Command function on my master page. So I either need to figure out a way to load my base page after the Button_Command function has had the chance to set a variable or I must call a function in my base page from the Button_Command function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否考虑过使用强类型母版页?
您还可以查看我对此问题的答案。
Have you considered using strongly typed master pages?
You can also check out my answer to this question.
我相信你可以用一个接口来做到这一点
所以子页面实现了这个接口
并且在母版页上
自从我使用网络表单以来已经很长时间了,所以我不能发誓这有效。我好像记得以前写过这样的东西。
I believe you can do this with an interface
So the child page implements this interface
And on the master page
It has been a long time since I worked with webforms however, so I can't swear that this works. I seem to recall writing something like this before.
您能否简单地将 Button_Command 逻辑封装到公共方法中,并从母版页上的 Button_Command 事件和子页面上的 Load 事件调用该方法?所以像
Could you simply encapsulate the logic that is Button_Command into a public method and call that method both from the Button_Command event on the Master Page and from the Load event on the child page? So something like