Simple Page Inheritance
You can probably make an educated guess at
what you have to do to make a page template, but either way this first demo is
going to give you a sample page for you.
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace AGASPTemplates
Public Class
HeaderTemplate : Inherits
Page
Public SampleText
As
New
Label()
Private Sub
Page_Init(ByVal
sender As
Object,
ByVal e
As
EventArgs)
Quicktext("<html><body>")
SampleText.Text = "There is no content"
Controls.Add(SampleText)
Quicktext("</body></html>")
End
Sub
Private Sub
Quicktext(ByVal
text As
String)
Controls.Add(New
LiteralControl(text))
End
Sub
End
Class
End
Namespace |
This looks very much like a code-behind page
doesn't it? All it does is just slap together a page with a Label on it.
If we add it directly as a code-behind, it will look like :
<%@ Inherits="AGASPTemplates.HeaderTemplate"
Src="TemplateCode.vb" %> |
Live Demo |
In case you are not familiar with that line
of code -
- Inherits specifies the Page
class to inherit the code from.
- Src specified the code file to
dynamically compile (with the inherited code in it). This saves you from
re-compiling the file into a library every time you make a change.