Monday, June 1, 2009

Creating a useful BasePage

When people start a new project,
creating a Base Page for all other pages is a must! I found a very interesting, yet simple and concrete article about the Base Page and some of the useful methods, which can be included there. This Base Page is great for avoiding code duplication and has a good level of error handling.

You can read the article here: ASP.NET Tip/Trick: Use a Base Page Class for All Application Pages

Page Refresh Handling
What I find useful adding to this Base Page, is a functionality for recognizing whether there is a Page Refresh occured (when the user presses F5 or Refresh button), because as you know, the Page Refresh actually does again what the last page post back was - all the events and stuff.
For example, when you click the button next of some results set you expect to move to the next page. What happens if you hit refresh after the rebinding? It actually executes again all the events from the previous post back, so it will move you to the next page, which you didn't want to. What is worse, it can break your application, because there can be no more results and no 'next' page. One way to handle this situation is to write some code in the Base Page so that you can track whether a Page Refresh occured and the other most common way is to stop/invalidate the page after refresh.

In conclusion,
I must remind that creating a common Base User Control is also useful and should be used as a best practice, too !

No comments: