Reputation: 3025
I want to be able to extend the System.Web.UI.Page class and then easily access those properties from the Markup. I know I can do it from the codebehind, but is it possible from the Markup? Take the following class.
public class MyBasePage : System.Web.UI.Page {
public bool DoesThisWork { get; set; }
}
Then I want to be able to access it from the html markup, perhaps in the @Page directive.
<%@Page Language="C#" DoesThisWork="False" ... %>
Of course the above Page is using the MyBasePage class instead of System.Web.UI.Page.
Upvotes: 2
Views: 1150
Reputation: 6426
I think the question is focused on how to use custom properties in the page directive - and the answer depends on whether you're using a Web Application project or Web Site.
For a Web Site, you need to assign CodeFileBaseClass to a non-partial class (under App_Code or in an external assembly). For Web Application, setting the Inherits directive should suffice.
Upvotes: 4
Reputation: 25083
Not directly from the HTML, as in your example, but you can do this:
<td>Result: <%=DoesThisWork.ToString()%></td>
Upvotes: 0
Reputation: 58293
Yes. You can access the base page's properties from markup, just as you can any other property on the page.
For example:
<a href="<%=MyBasePageProperty %>">this is a link</a>
Upvotes: 0