Generally, when we create a system
We have to write the same content for the Head part of every page. Is there a way for us to write the Head part into a control? Of course.
Let's write a class PageHead first.
Using System;
Using System. Web;
Using System. Web. UI;
Namespace
{
Public class PageHead: LiteralControl
{
Public PageHead ()
{
Base. Text = "<title>" + WebTitle + "-- Beibu Gulf News </title> \ n ";
Base. Text + = "<meta name = \" keywords \ "content = \" "+ WebKeywords +" \ "> \ n ";
Base. Text + = "<meta name = \" description \ "content = \" "+ WebDescription +" \ "> \ n ";
Base. Text + = "<meta name = \" author \ "content = \" tangyunle@163.com, QQ: 330611174 \ "/> \ n ";
Base. Text + = "<meta name = \" Copyright \ "content = \" kingeric | Tang yunle \ "/> \ n ";
Base. Text + = "<META HTTP-EQUIV = \" Content-Type \ "CONTENT = \" text/html; charset = gb2312 \ "> \ n ";
}
Private string _ webtitle;
Private string _ webkeywords;
Private string _ webdescription;
Public string WebTitle
{
Set {_ webtitle = value ;}
Get {return _ webtitle ;}
}
Public string WebKeywords
{
Set {_ webkeywords = value ;}
Get {return _ webkeywords ;}
}
Public string WebDescription
{
Set {_ webdescription = value ;}
Get {return _ webdescription ;}
}
}
}
In the HTML page, we can write
First, describe:
TagPrefix is the control label. For example, the current label is TT.
Namespace is the Namespace of the control.
Assembly is the Assembly name
<% @ Register TagPrefix = "TT" Namespace = "Namespace" Assembly = "TTStudio" %>
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TT: PageHeadid = "PageHead1" runat = "server"/>
</HEAD>
You can.
Success!
========= Kingeric Original article ================================ ===