Geeks With Blogs
Title Of Blog

For quite a while I have been using the concept of base pages when developing pages in ASP.NET applications. It is a wonderful method for exposing common functions to all of your applications pages and also overriding certain events for various purposes (i.e. dynamic themes). 

Recently I found out a new developer will be joining my team. This prompted me to review the applications code for readability and ease of maintenance. I began adding comments through out the code behind for all pages within the application. While doing so I noted that I had used common method names for such things as loading data, configuring controls, applying filters, etc.

Bringing a new developer on board, I wanted to make the transition as seamless as possible while also ensuring they follow existing coding practices we already have in place. While I could have created virtual methods for the common page methods allowing them to overridden, what I really needed was a way to ensure the new developer implemented the same methods for each and every page. Thus I created an interface to force the issue.

Now, every page not only inherits the base page class but also implements an interface. This provides every page not only common functions and overridden page events but also imposes rules for implementing certain common methods :-)



public interface BasePageInterface


/// Configures page based on users security permissions.

void CheckPermissions();

/// Configures Filter Form control for current page. 
Ensure you have set the FilteredGrid and PageAjaxManager properties of the FilterForm control in PageLoad!!! 

void ConfigureFilters();

/// Sets event handlers and default settings for controls on the current page.

void ConfigureControls();

/// Exports data bound to grid in selected format.

void ExportGridData(ExportFormat fmt);

/// Loads data and binds to grid.

/// Columns are turned on/off in grid depending on tab selected and users permissions. 

void LoadData();



Page code-behind class definition:

public partial class MyPage : BasePage, BasePageInterface

Note, you could not use an abstract class to accomplish this considering C# does not allow for multiple inheritance.  Nor could the base page class be abstract since it needs to inherit from the System.Web.UI.Page class in order to override page events.

Posted on Monday, January 31, 2011 10:31 AM ASP.NET , C# | Back to top

Comments on this post: Base Pages and Interfaces for ASP.NET Pages

# re: Base Pages and Interfaces for ASP.NET Pages
Requesting Gravatar...
The nice thing about using the interface is that there is nothing in the methods that your interface defines that requires a web page. This interface can be mocked for testing, pulled to a presenter, etc.

Interfaces are wonderful.
Left by Nick Harrison on Jan 31, 2011 12:37 PM

Your comment:
 (will show your gravatar)

Copyright © Jake Rutherford | Powered by: