I am wondering if you can set the MasterType VirtualPath dynamically in the codebehind? I have other code that dynamically changes the MasterPageFile using OnPreInit(), but it seems that the MasterType VirtualPath value has to be hard-coded into the .aspx.
What I would like to do is call a function from the master page, but since the master page is set dynamically, I can't hard-code the VirtualPath into the aspx because I'd be calling the function from the wrong master page if I do.
Anyone know if I can set the MasterType VirtualPath value dynamically in the OnPreInit()? Or can I dynamically cast "this.Master" before calling the function?
If all your master pages are derived from the same base type, then you can set your MasterType to that base type.
Anything else wouldn't make much sense because if your code depends on type of master page then it either have to be known at compile time so you can't really set it on the fly, or you can check for it at runtime using
if (this.Master is MyMasterOne)
var masterOne = this.Master as MyMasterOne;
// do something with masterOne
so you don't have to set it anywhere.
"My software never has bugs. It just develops random features."
Last Visit: 31-Dec-99 18:00 Last Update: 17-Sep-14 8:56