Articles → .NET → Page Template In .Net 1.1

Page Template In .Net 1.1









  1. Software requirement.
  2. Prerequisite knowledge.
  3. Creation of base class.
  4. Create a web page.
  5. Output.
  6. Conclusion.



Software Requirement





Prerequisite Knowledge




  1. How to create a website (or web application) using Visual Studio.
  2. What is Page class in .net.
  3. How render method works.
  4. How to inherit a class.
  5. 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


Picture showing the output of Page Template in .net 1.1
Click to Enlarge


Conclusion





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, September 15, 2010

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250