Last post Apr 13, 2010 09:23 AM by atconway
Apr 12, 2010 06:01 PM|greecemonkey|LINK
I have a baseclass that deals with all kinds of requests and is the 404 errorpage, so can serve blogs, lists, business profiles etc etc.
The baseclass is now to big, but can be divided up logically into sections in theory.
About 50% of the base class in check values and adding user controls into place holders. It is fast and works well, but it is just too messy now to work with properly.
Is there anyway I can create a new class inheriting the ui.page class and call it from the pageload and preinit events.
I mean something like this
Dim graham as new NewBaseClass
The problem seems to be when I have tryed it, that the pageloadstuff contains referance to me.master and master.findcontrol. I have done all the right imports and it does not seem to be able to be done
If this is not possible, and I guess it is probally now how can I move sections of my baseclass to new classes and create a more logical code stucture.
Apr 13, 2010 06:54 AM|lionadi|LINK
I'm not a VB programmer but in C# partial classes might help in this kind of situations. You can split up your code in more or more code files to make it more readable.
Apr 13, 2010 09:23 AM|atconway|LINK
Yes you can do this. You can either just use a plain class file or you can use a page that acts as your new Base page, but the actual page itself is never displayed; it is just used to create your new base class.
You don't even have to have the page's manually call this new class. If the existing page's inherit from this new class, and the new class inherits from System.Web.UI.Page, then all you need to do is Override the appropriate method (i.e. 'OnInit() ). In
this manner when all page's load, they will automatically call the overriden event in the new base class. Take a look below:
Public Class MyUIBaseClass
Protected Overrides Sub OnInit(ByVal e As EventArgs)
'Since this is a base class that is inherited by other pages
'it will be called upon opening by any page that inherits this page.
'Sample code implemented by inherited classes
'Maintain the browser's scroll bar positions on the client after postbacks.
Me.Page.MaintainScrollPositionOnPostBack = True
...and here would be the sample code from a Default.aspx that inherits the new class. Notice if you debug the code, it will 1st step into the 'OnInit' code in the inherited class:
Public Partial Class _Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Hope this helps!