开发者

Setting masterpage literal results in blank output

Wondering if someone can help me out here. New to ASP.NET.

Trying to output the PageName in a masterpage.

Masterpage has a Literal in which I am setting by accessing a property on the Mast开发者_开发问答erPage "PageTitle".

<head runat="server">
    <title><asp:Literal ID="litTitle" runat="server"/></title>
    <asp:ContentPlaceHolder ID="head" runat="server" />
</head>

The child page is like this:

<asp:Content runat="server" ContentPlaceHolderID="content">
<%
    MasterPage master  = Master as MasterPage;
    master.PageName = "Log in";
%>
</asp:Content>

And the property PageName is coded thusly:

    private string _pageName;
    public string PageName 
    { 
        get 
        { 
            return _pageName; 
        } 
        set 
        { 
            _pageName = value; 
            litTitle.Text = _pageName;
        } 
    }

I'm guessing this is because the page output has already been rendered, but as I say I don't know enough about ASP.NET. I guess I'm after something similar to PHPs ob_start().


You can access the page Title from the master page code-behind as follows:

protected void Page_Load(object sender, EventArgs e)
{
  string title = this.MainContent.Page.Title;
}

Note you will need to give your placeholder a name in the .Master file. If you want to retrieve the value other than the Title, do something like this: string title = (MyPage)this.MainContent.Page).MyValue;


You can find more about Master page and setting an property value in master page at below mentioned link.

http://www.simple-talk.com/dotnet/asp.net/asp.net-master-pages-tips-and-tricks/

I think here you can find your desire solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜