可以在UserControl(C#)中处理MasterPage事件 [英] Is it possible to handle a MasterPage event in a UserControl (C#)

查看:201
本文介绍了可以在UserControl(C#)中处理MasterPage事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到在内容页面处理MasterPage事件的代码,但是如果我将UserControl动态加载到页面中,我可以在UserControl中处理事件吗?



基本上我在MasterPage上有一个按钮,当它被点击时,我需要使UserControl做某事,例如显示文本或更改表单中的值。



否则,是否可能在同一页面上的另一个动态加载的UserControl中发生事件?我可以用MasterControl中的一个替换UserPage中的按钮。



感谢所有。

解决方案

这与这个stackoverflow问题



该问题的答案也适用于您的:您的网页了解其主人,并了解其子控件。它可以将子控件上的处理程序连接到母版页上的事件,因此当母版页甚至发生时,子控件可以执行必要的功能。


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.

解决方案

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.

这篇关于可以在UserControl(C#)中处理MasterPage事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆