Articles → .NET → Page Template In .Net 1.1
Page Template In .Net 1.1
- Software requirement.
- Prerequisite knowledge.
- Creation of base class.
- Create a web page.
- Output.
- Conclusion.
Software Requirement
Prerequisite Knowledge
- How to create a website (or web application) using Visual Studio.
- What is Page class in .net.
- How render method works.
- How to inherit a class.
- How to override a method.
Creation Of Base Class
using System;
using System.Web.UI;
public class PageBase: System.Web.UI.Page {
private string _pageTitle;
public string PageTitle {
get {
return _pageTitle;
}
set {
_pageTitle = value;
}
}
protected override void Render(HtmlTextWriter writer) {
// First we will build up the html document,
// the head section and the body section.
writer.Write(@ " <html>
<head>
<title> " + PageTitle + @" </title>
</head>
<body > ");
// Then we allow the base class to render the
// controls contained in the ASPX file.
base.Render(writer);
// Finally we render the final tags to close
// the document.
writer.Write(@ " </body>
</html>");
}
}
Create A Web Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<form id="SimplePageInheritance" method="post" runat="server">
<p>
This is the sample of the page with master page like feature
without using master page.
</p>
</form>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default: PageBase {
protected void Page_Load(object sender, EventArgs e) {
PageTitle = "test";
}
}
Output
Click to Enlarge
Conclusion