views:

29

answers:

3

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.

A: 

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>
Gabriel McAdams
A: 

Not directly from the HTML, as in your example, but you can do this:

<td>Result: <%=DoesThisWork.ToString()%></td>
egrunin
A: 

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.

Nariman