I'm working on a series of ASP.Net web pages for an existing site, and part of that task is to provide a way for the user to print the content of the page. Due to the architecture of the pages, it was convenient to create a base class that handled common functionality. I initially got the printing working on all of the pages via a button on each page) and its associated click handler, but I decided that I wanted to display the printable content in a separate window.
property. In order to implement my idea, I had to make a couple of changes:
0) Create a new
1) Add the PostbackUrl property to the aspx Button element on all of my other pages, and set the value to the newly created
2) Modify the base page object to include an (empty) overridable method called
3) Override that new method in any page that had the ability to print its content.
4) Moved my print button event handler code to the new overriding method
After all that was done, I added the following code to the
event handler in the
code behind (sorry, I'm using VB so that's what you're gonna get here):
Essentially, we're using polymorphism to execute the appropriate version of the
method on the previous page. If I was only using this aspx page from a single page, I could just cast
to the actual class in the code behind for the given page.
This tip illustartes that a) you can have your cake and eat it to, and b) don't be afraid to look outside the box to which you're currently confining yourself.