Class PageBase
Using DotNetNuke as an example for this tutorial you can see there is a class
called PageBase located in the Shared folder (PageBase.vb). Within this class
you can see that the PageBase class inherits from the standard
System.Web.UI.Page class within the .NET framework.
Public MustInherit Class PageBase
Inherits System.Web.UI.Page
Investigate this class further and you'll see it is broken up into various
regions containing public properties, public methods, and corresponding private
methods and properties. Let's look at one specific method SetLanguage:
Public
Sub SetLanguage(ByVal
value As String)
' save the pageculture as a cookie
Dim cookie
As System.Web.HttpCookie =
Nothing
Try
cookie = Response.Cookies.Get("language")
Catch
' Response is not available in
this context
End
Try
If (cookie
Is Nothing)
Then
If value <>
"" Then
cookie = New
System.Web.HttpCookie("language", value)
Response.Cookies.Add(cookie)
End If
Else
cookie.Value = value
Response.Cookies.Set(cookie)
If value =
"" Then
Response.Cookies.Remove("language")
End If
End
If
End
Sub
The SetLanguage method of DNN checks for the language of the pages and
manages the cookie settings for the current language.
Okay, so big deal we have a class called PageBase that has methods like
language management, security checking, control management, and some other
things. How is this going to benefit you as a developer? Let's look at any one
of the pages within DNN to see what it's doing with this PageBase class, for
example the RSS module (RSS.aspx.vb file):
Partial Class
RSS
Inherits Framework.PageBase
You see what it's inheriting? So not only does the page get all the great
features provided by the framework via the PageBase since it inherits from the
System.Web.UI.Page it also now gets all
the custom methods, and properties that DNN provides within the PageBase class.
This enables all the aspx files within the application to have one centralized
code base for shared methods like security handling, language, and layout
features. Rather than updating each page individually, you now centralize all
the code within a single base page class.