Is it possible to handle a MasterPage event in a UserControl (C#)

怎甘沉沦 提交于 2019-12-25 04:22:22

问题


I've seen code to handle MasterPage events in the content Page, but if I'm loading a UserControl dynamically into the Page, can I handle the event in the UserControl instead?

Basically I have a button on the MasterPage, when it's clicked I need to make the UserControl do something, such as display text or change a value in a form.

Failing that, is it possible to make an event from one dynamically loaded UserControl fire in another on the same page? I could then replace the button in the MasterPage with one in another UserControl

Thanks all.


回答1:


This is very similar to this stackoverflow question.

The answer to that question should also apply to yours: your Page knows its master and knows its child controls. It can wire-up a handler on the child control to an event on the master page, so the child control can perform necessary functionality when the even occurs on the master page.



来源:https://stackoverflow.com/questions/3524193/is-it-possible-to-handle-a-masterpage-event-in-a-usercontrol-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!