Setting Label's text attribute to the page title's text.

Is there a way to programmatically set a label's text attribute to the current page's title attribute? Such as (pseudo code):


private void Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here lblPageTitle.Text = PageTitle.Text.Attribute(); }
11/27/2006 11:54:37 PM 93655 articles. 5 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 3

lblPageTitle.Text = Page.Title();


Mike Banavige

Need a site code sample in a different language? Try converting it with:
11/28/2006 1:15:22 AM

Thank you for the reply, however, Page.Title is not available. Perhaps this is a 2.0 feature? I'm still using 1.1, any help would be greatly appreciated!

Sincerest regards,
Brian Sheahan

11/28/2006 3:09:31 AM


      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>

  protected void Page_Load(object sender, EventArgs e)
        Page.Header.Title = Label1.Text;

11/28/2006 3:38:22 AM

Again, thank you for the response, but I get the following error:

  'System.Web.UI.Page' does not contain a definition for 'Header'

11/28/2006 3:42:07 AM

It's a ASP2.0 feature.

 But if you are simply changing the content of a label to the page's title, you can do it on client side with javascript, which is actually better because from the time the server thinks title is xyz to the time the browser finishes processing, javascript along the way may have changed title from xyz to abc.

Can you zoom out your problem alittle? There maybe an alternative work around.



Debugger is my best friend. (
11/28/2006 3:56:13 AM


in 1.1

add runat="server" to <title>Untitled Page</title>

like <title id="PageTitle" runat="sever">Untitled Page</title>

in this way, make the title as a server control,then add protected System.Web.UI.HtmlControls.HtmlGenericControl PageTitle; to the cs codebehind

in Page_Load event



have a try, hope it helps

11/28/2006 5:26:29 AM

Lots of great replies! Thank you!!

However, this one doesn't do it either. :(

The error I get is with regards to the protected control I'm adding to the CS code behind. 'System.Web.UI.HtmlControls.HtmlGenericControl' works out great, but when I append '.PageTitle;' to it, it says the ';' cannot be used. The specific error: "Invalid token ';' in class, struct or interface membership declaration." Funny thing is that Intellisense doesn't pick up PageTitle as an option when I type out the declaration (which doesn't mean anything, so I still debugged and it erred out).

To answer the question previously to this last post:

I have a 'template' of sorts where there is this banner of sorts that I don't want to have to manage if I'm already managing the page's title. They will be the same at all times. If it were possible to either set this label control within this banner to the page's title or the page's title to the label control within this banner, that would be great and save me a bunch of time throughout the site.

Technologies used:

C# 1.1

Thanks for all your help and support!

11/28/2006 2:15:53 PM


give the title in the HTML view the server controls:

<title id="PageTitle" runat="server">Your custom title here...</title>

next, declare the protected control:

protected System.Web.UI.HtmlControls.GenericHtmlControl PageTitle;

Then, in the Page Load event, assign it to the label control:

lblPageTitle.Text = this.PageTitle.InnerText.ToString();

Thanks to all who contributed, the combined answers got me to where I needed to be.


11/28/2006 4:13:55 PM

Similar Artilces:

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

How do I handle Updating a Label's Text When it's in a Template?
As it stands right now.  I get the error 'Object reference not set to an instance of an object.' for the following line of code.vd_lbl_StatusMess.Text = "Record Updated" This label is located in a Template.  I just want to update the text property.  Thats all!!  Working with Templates has been a nightmare!!  Please help! "Sometimes I spend so much time going the wrong direction on a problem. K.I.S.I.S = Keep It Simple I'm Stupid :)"Matt Is the Template in a Formview or Gridview?  I'm asking because if 'ts a Formview, you have to find t...

how to control a RadioButtonList's Listitem's text show according database's field
Hi my page has a repeater control,in repeater has a RadioButtonList control now i want to let the RadioButtonList has four Listitem,every Listitem's text is a database's field so the listitem can show dynamic according every record how can i work out my problem thanks a lot  hello dearbound your RadioButtonList to database if i m not clear fell free 4 replySatyabrat SinghB.E.(C.Sc.)Web developer Livetek Solution Dont forget to click "Mark as Answer" on the post that helped you. yes.i bound the radiobuttonlist to a dataset but how to display the ...

Setting TextBox's Text to Tabpage as its title/display text
hi, I am creating a tabpage dynamically and I am trying to set the text for this tabpage which is entered by the User in a TextBox. Problem is, though tabpage is getting created i am unable to get the Text/title for it. Any Help.......... Regards.   put the text is a session or in a db and load on page.load you should be ok.Joël Hébert [MVP ASP.NET]Opulent ASP Development Inc.www.opulentasp.comOttawa,CanadaClick "Mark as Answer" on the posts that helped you to help future readers to get the solutions Hi, Based on my experience and research, I suggest th...

Set page's title from a database text field
How can I set the page's title based in a database text field?   Page presents data using a Formview that is filtered by a numeric QueryString.   I very appreciate you help.     Ernesto In your code, just set:Me.Title = "MyPageTitle" ' use whatever string you get from DB ---------------------------------------MCP - Web Based Client Development .NET 2.0 I very appreciate your help but the problem is that I am trying to use the functionality of the ASP.NET 2.0 so I am using a FormView control like this <%@ Page Language="VB" MasterPageFile="~/maste...

Setting a parent page's label control text from a user control
I have a .net 2.0 site where I'll have the same form for user input on a number of pages. I plan on using a user control for this. The catch is if the user doesn't input the data properly I want to write the error message to a label control on the parent page, not in the user control. This is because the design for each parent page is different enough that we need to display the error message in a different part of the page. I've seen a couple of websites that mention using a base page that all my pages could inherit from to have a user control interact with the parent page. This...

How to set a Master Page's control's property through content page on a postback event?
Hi all, i m using a master page in my application. i have a panel on master page and a tab container with three tab panels on content page. i want to set/change  the visibility of the panel control when the tab is changed on the content page. By default the panel is invisible. To implement this i executed the following steps: 1. Set AutoPostBack of tacontainer to true 2. Wrote an event handler for ActiveTabIndexChanged event of the tab container 3 Wrote the following code on Tab changed event   if (TabContainerEmpPerformance.ActiveTabIndex == 1) { ...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

It's Linux !? No, it's BSD ! No, no, it's...
kFreeBSD a Debian distro using the FreeBSD kernel ! ObiWan wrote: > kFreeBSD > > > > a Debian distro using the FreeBSD kernel ! Why use a BSD kernel? I hope the reason is more than, just because they can. It's easy to understand why the would want to use Debian packages. :) -- Jimmy Johnson Registered Linux User #380263 >> kFreeBSD >> >> >> ...

changes made from one user's webpart's page, effects all user's
 I am just doing this offline right now in Visual Web Developer Express 2008I created the login inonce in the memberpage area, people can modify their webpart page. I created several users to test this out.  I loaded it in a browser.When I make changes as logged in user "A" .  Then logout and login as user "B", user "B,s" webpart page has been changed to user "A".This goes true for whomever I log in as.  It changes for everyone.Is there something specific I need to do in order to get everyone's changes to be unique for them...

Insert text of Format (People'S OR Republic'S)
 I am not actually able to add Such type of text like People'S OR Republic'S Where 'S is der i am geting error while inserting through  Insert statement.What is the problem actually? I would wager that you are building the insert statement by concatenating strings together. Not only does doing that produce your symptom, but it also makes your system very vulnerable to sql injection attacks that can steal or destroy your data. Do a search on this forum for "parameterized query" or "parameterized queries".  You will find instructions for how t...

superreview requested: [Bug 397222] Bogus 'for' attributes shadowing ' control' attributes on <label>s
Phil Ringnalda <> has asked <> for superreview: Bug 397222: Bogus 'for' attributes shadowing 'control' attributes on <label>s Attachment 281988: Fix v.1 ------- Additional Comments from Phil Ringnalda <> These appear to be the only ones that aren't included in bug 397097 (which is already having to reach pretty far outside its remit, withou...

Web resources about - Setting Label's text attribute to the page title's text. -

Resources last updated: 12/12/2015 12:10:12 AM