Wednesday, 4 November 2009

Using the @MasterType directive instead of the @Page directive with MasterPageFile=""

Just a quick snippet for future use.  When referencing a master page within your aspx file its best to use the @MasterType directive rather than the MasterPageFile="" attribute of the @Page directive.  Doing so will allow strongly typed access to any methods you've put in the master page rather than having to do something ugly.  Example:


((DefaultLayout)this.Master).SetPageHeading("This heading is set from inside Default.aspx");

becomes:

Master.SetPageHeading("This heading is set from inside Default.aspx");

Much better dont you think?

0 comments:

Post a Comment