如何从内容页访问用户控件在母版? [英] How to access a user control in a masterpage from a content page?

查看:109
本文介绍了如何从内容页访问用户控件在母版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说,我有一个母版页页眉的用户控件,并希望改变取决于什么内容页母版页内加载的用户控件的属性。我怎么可能去呢?

Lets say that I have a header user control in a master page, and want to change a property of the user control depending on what content page is loaded inside of the master page. How might I go about this?

谢谢!

推荐答案

您可以使用两种方法。第一种是通过使用 Page.Master.FindControl(控件ID')。然后,你可以将它转换为用户控件的类型。第二种方法是通过增加一个<%@ VirtualPath的MasterType =的TypeName =%GT; 标记到你的aspx页面。在 VirtualPath 的虚拟路径添加到主网页,并在类型名的类。然后,您可以访问智能感知的一切。

You can use two methods. The first is by using Page.Master.FindControl('controlID'). Then you can cast it to the type of your user control. The second method is by adding a <%@ MasterType VirtualPath="" TypeName=""%> tag to your aspx page. In the VirtualPath add the virtual path to the master page, and the class in the TypeName. You can then access everything with intellisense.

这篇关于如何从内容页访问用户控件在母版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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