开发者

Referencing a public property in current master page, from content page

I hope someone can help me.

I have a header page that has a logo, menu, a search box, etc. For certain pages, I want to be able to hide some parts of that header.

I've created three master pages and three headers, but the differences in the headers are very small, so I'd rather not maintain three copies of the header.

I want to set a property in the master page, that I can reference in the header and hide content appropriately. The problem of course is that the header is used on pages that use sev开发者_如何学编程eral different master pages, and the only way I can find to access properties on a master page is to use

<%@ MasterType VirtualPath="~/masters/SourcePage.master" %>

But that links to a specific master page, so it doesn't really help me. Is there a way to reference the currently used master page instead, and access its public properties?

Thanks.


Sorry I seem to have been thinking about it backwards. The header is in all the master page, so I can set a property on it from the master page. Blame the lack of sleep, and the lack of caffeine in this place! :P


You should be able to do something like

var result = ((MasterPageClassName)Page.Master).MasterPageClassProperty;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜