开发者

ASP.Net - Can I Access My BasePage Properties From Within Markup?

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.


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.


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>


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜