inheriting the .aspx pages?
Can we inherit th开发者_JS百科e aspx page into another aspx page. If yes how can we do that, Thank you.
I think there are two things you should consider here::
1.Create a new base page type, and have your codebehind classes inherit from that, e.g.:
public abstract class MyPageBase : System.Web.UI.Page
{
// Implement custom shared logic here.
}
2.Move some of your page control logic into partial controls that you can inject into other pages.
I don't think so. You can however, create a master page and use it in the pages you want. That is the way "inheritance" of aspx pages works.
Master page tutorials:
http://www.asp.net/master-pages/tutorials
You can inherit the code (i.e. the classes derived from System.Web.UI.Page), but you cannot inherit the markup.
For markup "inheritance", use ASP.Net mechanisms such as User Controls (ascx) or MasterPages, as other responses suggested, or create controls dynamically.
I am not entirely sure that I understand your question correctly, but you surely can inherit a ASPX page. In your code behind file for a page you have a class declaration where the page inherits from System.Web.UI.Page
. If you want to use a different base page, you could simply make another base class that inherits from System.Web.UI.Page
and change the code behind defined classes inherit from you new base page.
The problem will of course be to make an appropriate layout shared elements and if that is your main concern you are probably better of using master pages.
精彩评论