ASP.NET: Setup the Page Title from Web.Sitemap

Wednesday, August 04, 2010

ASP.Net allows you to associate a sitemap file with your project. You can add this file as a Web.Sitemap in the web project. This file could be used with the ASP.Net navigation controls to create menu, tree view or a site map path on your website. One of the other things where this file comes handy is when you want to dynamically assign title to your pages. This is a fairly common requirement when you use master pages and don't want to modify additional parameters on individual pages. Here's the code you should add into your master page's .cs file:

// C#
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);

// Setting Page Title from SiteMap
SiteMapNode node = SiteMap.CurrentNode;

if (node != null && !string.IsNullOrEmpty(node.Title))
{
Page.Title = "App Name | " + node.Title;
}
}
' VB.NET
Protected Overrides Sub OnInit(e As System.EventArgs)
MyBase.OnInit(e)

' Setting Page Title from SiteMap
Dim node As SiteMapNode = SiteMap.CurrentNode

If node IsNot Nothing AndAlso Not String.IsNullOrEmpty(node.Title) Then
Page.Title = "App Name | " + node.Title
End If
End Sub

The above function adds the associated title associated with the url of the page.

1 comments:

parkiannello said...

전자우편주소, 사업자등록번호, 통신판매업 신고번호, 개인정보보호책임자등을 이용자가 쉽게 알 수 있도록 00 사이버몰의 초기 서비스화면(전면)에 게시합니다. 다만, 약관의 내용은 이용자가 연결화면을 통하여 볼 수 있도록 할 수 있습니다. 최근 계속되는 신규 카지노들의 먹튀 사기가 일어나고 있습니다. 날이 갈수록 카지노 유저들의 고민이 깊어져 온라인카지노 가고 있습니다. 먹튀로 인해 카지노 선택이 힘드신 분들을 위해 저희 사이트가 등장 하였습니다. 저희 사이트는 우리카지노 공식 홈페이지로 100 percent 안전합니다.

Post a Comment