Master page override
HejJeg prver at override min masterpage's contentholder, sledes at jeg p andre sider som referere til denne masterpage kan angive en ny:
- <titel>tekst</titel>
- <meta name="keywords" content="tekst">
som passer til de forskellige asp sider.
pseudo:
________________________________
Masterpage aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<asp:contentplaceholder id="headContent" runat="server">
<title><% =m_HtmlTitle %></title>
<meta name="keywords" content="<% =GetKeywords() %>" />
<meta name="description" content="" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<link href="Mainpages.css" type="text/css" rel="stylesheet" media="screen" />
</asp:contentplaceholder>
</head>
<body>
<form id="form1" runat="server"> ..........................
______________________________________________________
Masterpage codebehind:
_______________________________________________
Partial Class _Default
Inherits System.Web.UI.MasterPage
Protected m_HtmlTitle As String
Protected m_keywords As StringCollection = New StringCollection()
Public Property HtmlTitle() As String
Get
Return m_HtmlTitle
End Get
Set(ByVal value As String)
m_HtmlTitle = value
End Set
End Property
Public Property Keywords() As StringCollection
Get
Return m_keywords
End Get
Set(ByVal value As StringCollection)
m_keywords = value
End Set
End Property
Public Sub Page_Load(ByVal source As Object, ByVal e As EventArgs)
m_keywords.AddRange(New String() {".NET", "ASP.NET"})
End Sub
Public Function GetKeywords() As String
Dim sb As StringBuilder = New StringBuilder()
For Each nextString As String In m_keywords
sb.AppendFormat("{0},", nextString)
Next
Dim minValue As Integer = 0
Dim substractValue As Integer = 1
If sb.Length > minValue Then
sb.Length = sb.Length - substractValue
End If
Return sb.ToString()
End Function
End Class
_______________________________________________
Andre aspx sider
___________________________________________
<asp:content id="newHeadContent" contentplaceholderid="headContent" runat="server">
<title>Forside</title>
<meta name="keywords" content="tekst tekst" />
</asp:content>
________________________________________________
<title></title> og <meta name="keywords" content="" /> indeholder ikke noget.
Nogen forslag?
Mvh
techie
