How to Execute Base Class's Method Before Implementors's Method?

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-05-12T11:48:28Z Indexed on 2010/05/12 20:14 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

I have the following page

public partial class GenericOfflineCommentary : OfflineFactsheetBase
{
}

where OfflineFactsheetBase is defined as public class OfflineFactsheetBase : System.Web.UI.Page { public OfflineFactsheetBase() { this.Load += new EventHandler(this.Page_Load); this.PreInit += new EventHandler(this.Page_PreInit); }

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["data"] != null)
        {
            this.PageData = StringCompressor.DecompressString(Request.QueryString["data"]);
            this.ExtractPageData();
        }
    }
}

OfflineFactsheetBase has the following virtual method:

public virtual void ExtractPageData()
{
    // get stuff relevant to all pages that impmement OfflineFactsheetBase 
}

which is implemented in all pages that impmement OfflineFactsheetBase as follows:

public partial class GenericOfflineCommentary : OfflineFactsheetBase
{
    public override void ExtractPageData()
    {
            // get stuff relevant to an OfflineCommentary page.
    }
}

Currently, only GenericOfflineCommentary's ExtractPageData() is firing. How can I modify this to first run OfflineFactsheetBase's ExtractPageData() and then GenericOfflineCommentary's?

edit: I'm trying to avoid having to call base.ExtractPageData() in every implementor. Is this possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET