Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you cast from Page.Master to a specific master page in ASP.NET

Tags:

asp.net-2.0

I have a BasePage which inherits from System.Web.UI.Page, and every page that inherits the BasePage will have the same master page.

How do I cast the Page.Master of the BasePage to the specific master page so I can access properties on it?

like image 234
Nathan Smith Avatar asked Dec 27 '25 14:12

Nathan Smith


1 Answers

A better way is to add the MasterType property to the pages that use that master. Then you can simply access the master page properties through the page object.

<%@ MasterType VirtualPath="~/site.master" %>

You just use this in your code:

this.Master.propertyName

To access the property of the master page for the current page.

like image 123
Jason Stevenson Avatar answered Dec 31 '25 04:12

Jason Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!