user2224780
user2224780

Reputation: 71

ASP.NET page inheritance: Controls from base class are not initialized

I am using a base page and an inherited page. The base page is working fine.

In the inherited page I have the following @Page-directive:

<%@ Page Title="" Language="C#" AutoEventWireup="True" Inherits="SubPage" CodeFileBaseClass="BasePage" CodeFile="SubPage.aspx.cs" %>

and the following code-behind file

public partial class SubPage: BasePage

The problem is that in Page_Load of the base class, all Controls are null.

A master-page is no solution for me in this case.

Upvotes: 3

Views: 2627

Answers (1)

zhuber
zhuber

Reputation: 5524

Inhert your code-behind as you would normally using:

public partial class SubPage: BasePage

and in markup do something like:

<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="SubPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    Main content.
</asp:Content>

http://msdn.microsoft.com/en-us/library/vstudio/wtxbf3hh(v=vs.100).aspx

EDIT:

If masterpage is not what you want you'll have to do:

<%@ Page Title="" Language="C#" AutoEventWireup="True" Inherits="BasePage" CodeFileBaseClass="BasePage" CodeFile="SubPage.aspx.cs" %>

and copy whole markup of BasePage below. Code-Behind is inherited same way again:

public partial class SubPage: BasePage

Upvotes: 1

Related Questions