开发者

Get Page.Master Instance without Cast

I am trying to get a master's page instance without cast开发者_如何学运维.

Something like this but without cast

var masterPage = (MasterPageName)Page.Master;
        if (masterPage != null) {
            masterPage.Foo = false;
        }

Is there any workaround for this?

thanks


I would make MasterPageName to implement an interface IFoo which has the boolean Foo defined, so in your code above you could check if Page.Master is IFoo and you do not need any cast.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜