Inheriting directly from the base Page class (System.Web.UI.Page) is not good practice. Instead, create a new base Page class that inherits from System.Web.UI.Page, and inherit all of your pages from your new base page!
namespace MyNamespace {... public class Page : System.Web.UI.Page{...}}
namespace MyNamespace {... public class SomePage : MyNamespace:Page{...}}
Dino Esposito has posted a MSDN article, “Build Your ASP.NET Pages on a Richer Bedrock”, that lists a few immediate examples of functionality you can add to your pages by simply modifying your base Page class.
* Trapping the Browser Refresh - Why is this important? End-users don't think twice about using refresh or navigating through their history. Unfortunately, this includes moments that some data-changing postback just occurred, like:
* A final check-out in an e-commerce app
* Deleting a record of some type
* Posting a message
You get the idea... refreshing a page can mean reposting the last request, which can be dangerous, and a difficult bug to kill on all pages where it wasn't handled appropriately. With an inherited page architecture, you can trap the request, and handle it appropriately in one place!
* Status bar or message on long requests - Hourglasses are boring and annoying. In Wireless areas, when connections are weak or intermittent, they're obnoxious. For usability purposes, some type of status bar or message is appropriate on long requests. These features are difficult to add individually to such requests. Once again, inheritance comes to the rescue with a static method that takes two urls for processing: one for the status message (”Please wait...”), and the other as a destination message (”Process complete...”).
* SetFocus(), OnEnter(), Popups on page load - Dino gives an example for setting focus to a control on page load by writing the javascript from the base Page class. This technique can be applied for any common OnLoad javascript events, to be accessible to all pages that inherit from the base page.
Note: ASP.Net 2.0 will have a SetFocus method!
I got some great ideas (as usual) from Dino's article. ASP.Net is like any other object-oriented language: Using inheritance saves time and trouble, and enables you to write your functionality into your app once, keeping things clean and easy to manage.
Print | posted on Wednesday, September 22, 2004 9:31 AM