This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.

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?

1 comment:

  1. If you have any technical or readability issues with the new design, please leave a comment below and I'll look into it. Thanks! time and billing software

    ReplyDelete