开发者

Extend MasterPage class in child page

I am programming a website with ASP.NET/C#. I am using master pages for simplifying the layout design.

I have a BaseMasterPage.master master page, which has some code behind in an .master.cs file defining among others a BaseMasterPage class (extends System.Web.UI.MasterPage) and some methods in it (page_load,...). What I want to do, is to have a child page with an associated ChildPage class that extends BaseMasterPage, in order to reuse some of the methods in BaseMasterPage.

But this throws several errors. E.g ASP.child_aspx.GetTypeHashCode(): No matching method found for overwriting, same as for ASP.child_aspx.ProcessRequest(System.Web.HttpContext), ASP.login_aspx does not implement the field S开发者_Python百科ystem.Web.IHttpHandler.IsReusable and so on.

I'm quite new to ASP.NET, so I guess it is just a beginner mistake... Could anybody tell me what I am doing wrong?

Thanks in advance for your answers.


Pages and MasterPages are different types of things. You are having problems because an ASPX page cannot inherit from System.Web.UI.MasterPage. It should ultimately inherit from System.Web.UI.Page.

So your plan of having both the master page and the content page (aspx) inherit from the same base class will not work.


I think you can define the class of your child page like this :

public partial class Default : ChildPageClass.

In your ChildPageClass :

public class ChildPageClass : YourMasterPageClass.

Can you try this ?

I'm not sure of this solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜