开发者

Can I know what page is in my master page's ContentPlaceHolder?

All the Google finds I ran into tell me how to use FindControl to access a control on the master from the content page itself.

However, what I'm trying to do is the opposite. From the master page, I want to reference whichever child page is in the ContentPlaceHolder.

Why you ask. I want the master page to know which tab should be active depending on the content Page currently in the placeholder. This lets me avoid having each page to reference the master pag开发者_JAVA技巧e and allow them to change the active tab; that should be the master page's job (if there's a way it can know whom it's enclosing).

Thanks. No rants please.


If you are looking to get the instance of the executing page class, you can retrieve it from the current HTTP context:

var page = HttpContext.Current.CurrentHandler as Page;

From there, you can navigate the page's control tree, call FindControl(), and so on. Be cautious about page lifecycle, though, as master page events tend to fire before their page event counterparts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜