profanis
profanis

Reputation: 2751

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

Upvotes: 1

Views: 523

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

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.

Upvotes: 1

Related Questions