c# - Accessing different Masterpages from Base Class -
i have application uses 2 master pages. 1 main pages , 1 popup pages. these both inherit masterpages
public partial class mainmasterpage : system.web.ui.masterpage { userbo objuser = null; public userbo getcurrentuser() { userbo userbo = new userbo(); ..... ..... return userbo; } } public partial class popupmasterpage : system.web.ui.masterpage { userbo objuser = null; public userbo getcurrentuser() { userbo userbo = new userbo(); ..... ..... return userbo; } }
so far good. content pages inherit base class. base class has method calls getcurrentuser base class.
public class basepage : page { //..... protected userbo getcurrentuserfrommasterpage() { this.master elsa.masterpages.mainmasterpage master = (elsa.masterpages.mainmasterpage )this.master; return master.getcurrentuser(); } }
so here can see base page casts masterpage
, calls getcurrentuser
.
just background... masterpages current user logged system , draws using info. if user in session gets otherwise loads database. dont want content pages same wanted base page current user content page master.
however problem is, because there 2 master pages , web pages derived base page.. need able cast correct master.
public partial class mymainpage : elsa.pages.basepage { private long _userid = -1; public partial class mypopuppage : elsa.pages.basepage { private long _userid = -1;
if put in mastertype directive can call method in content page correct master. dont want call content common method need in base.
so know how handle this. thinking on deriving basepage again popupbasepage , on writing getcurrentuserfrommasterpage()
cast popup master. or pass basepage constructor tell cast to.
i want keep impact web pages minium have lot of web pages.
thanks m
you can insert masterpage base class 2 current ones:
public partial class sitemasterpage : system.web.ui.masterpage { .... // getcurrentuser } public partial class mainmasterpage : sitemasterpage { .... } public partial class popupmasterpage : sitemasterpage { }
this allow implement other common features , markup (include of css files) in 1 place well.
Comments
Post a Comment