简体   繁体   中英

Setting title in a Base Master Page

I have a Base Master Page where I set my title.

The problem is a few select pages need the title to come from a different source.

So I need to get a value from an ASP.NET literal and pass it to the Base Master Page in order to set the title.

Is this possible?

this is how my code looks in the CS code behind, but its still now getting to title from the content page

  else if (PageID == 200|| PageID == 201 || PageID == 202 || PageID == 203)
                    {

                    ContentPlaceHolder cph =this.Master.FindControl("ContentPlaceHolder") as ContentPlaceHolder;
                    Label lit = cph.FindControl("ArtileTilte") as Label;
                    BrowserTitle = lit.Text;


                    }

Make a virtual property that retrieves the title in the base master page (this one contains the default behavior) and override it in the derived master page classes (this is where you define a different behavior - for example, getting the title from a literal). The link below contains an example of doing this:

http://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.100).aspx

让我们假设控件保持标题是Label,然后为了访问母版页上的标签,请执行以下操作:

((Label)Master.FindControl("label")).Text = "My Title";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM