从主机页调用用户控件中的事件处理程序
我在用户控件中有一个下拉列表,当下拉列表的选定索引发生更改时,我想在托管此用户控件的主机页的基础上执行不同的功能,例如,当主机页是我希望事件加载位置的位置时下拉列表中的所选项目,当托管页面是服务时,我想加载下拉列表中所选项目的服务。实现这一场景的最佳方法是什么?
I have a dropdownlist in a user control and i want to perform different functions on the basis of the host page that hosts this user control when the selected index of the dropdownlist changes e.g. when the host page is locations i want the event to load locations for the selected item in the dropdown, when the hosting page is services i want to load services for the selected item in the dropdown. What is the best possible way to achieve this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的内容对您有帮助吗?
Is the below helpful for you?
每当您想要向父控件通知某些内容时,一个好的做法是从子控件引发一个事件,父控件将向该子控件注册并执行所需的操作。
另一方面,将父控件的引用传递给子控件以便子控件可以调用父控件的方法是一种不好的做法。
Whenever you want to notify something to a parent control, a good practice is to raise an event from a child control to which parent control registers and does what is needed.
On the other hand, it is a bad practice to pass a reference of parent control to child control so that child can invoke a method on parent.