Tuesday, 15 April 2014

ASP.NET can't set page title from content page -



ASP.NET can't set page title from content page -

i have page

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class charts : system.web.ui.page { protected void page_load(object sender, eventargs e) { page.header.title = "some title"; } } <%@ page title="" language="c#" masterpagefile="~/masterpage.master" autoeventwireup="true" codefile="charts.aspx.cs" inherits="charts" %> <asp:content id="content1" contentplaceholderid="head" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server"> <ul> <li><a href="reportmissiontype.aspx">reportmissiontype</a></li> </ul> </asp:content>

and in masterpage.master there title tag defined

<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>title</title> <asp:contentplaceholder id="head" runat="server"> </asp:contentplaceholder> <meta name="keywords" content="" /> <meta name="description" content="" /> </head>

but still when seek set title content page (above) page.header.title = "some title"; gives me error says page.header.title object reference not set instance of object.

why can't set title content page ?

in order access children of head element, need set runat="server" attribute on head element.

<head runat="server"> <title>title</title> ... </head>

asp.net master-pages

No comments:

Post a Comment