473,609 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change page's title dynamically

Hi, is there a way to change the page's title in code behind (C#)?

I want to change this part:
<HEAD>
<TITLE> Can be changed dynamically. </TITLE>
</HEAD>

Thanks,
Guogang
Nov 18 '05 #1
6 5562
>Hi, is there a way to change the page's title in code behind (C#)?

Make the text of the title a label.
In your code behind set the label's text.

--
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Wil Moore III, MCP Site : www.quicksitedesign.com?em
Application Developer Site : www.digitallysmooth.com?em
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Nov 18 '05 #2
Well, it works. Never thought I can do this. :)

Only thing I want to change is that I need to use "Literal" instead of
"Label", otherwise, the title will have <span> around it.

"Laidbak" <la*******@hotm ail.com> wrote in message
news:Op******** ******@TK2MSFTN GP09.phx.gbl...
Hi, is there a way to change the page's title in code behind (C#)?


Make the text of the title a label.
In your code behind set the label's text.

--
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Wil Moore III, MCP Site : www.quicksitedesign.com?em
Application Developer Site : www.digitallysmooth.com?em
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
Nov 18 '05 #3
Give your title tag an id and runat attribute. then declare it in code
behind And then you can retrive data from a dataset and set the inner text
property equal to the text or whatever.

<title id="PageTitle" runat="server"> </title>

Protected WithEvents PageTitle As HtmlGenericCont rol

PageTitle.Inner Text = ds.Tables(0).Ro ws(0).Item("Art icleTitle").ToS tring

"Guogang" <nospam@no_such _domain.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Hi, is there a way to change the page's title in code behind (C#)?

I want to change this part:
<HEAD>
<TITLE> Can be changed dynamically. </TITLE>
</HEAD>

Thanks,
Guogang

Nov 18 '05 #4
this works , but VS has the annoying habit of removing the runat="server"
from <TITLE> tags when it feels the urge.
"Showjumper " <sh*******@grkj ashdjkf.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Give your title tag an id and runat attribute. then declare it in code
behind And then you can retrive data from a dataset and set the inner text property equal to the text or whatever.

<title id="PageTitle" runat="server"> </title>

Protected WithEvents PageTitle As HtmlGenericCont rol

PageTitle.Inner Text = ds.Tables(0).Ro ws(0).Item("Art icleTitle").ToS tring

"Guogang" <nospam@no_such _domain.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Hi, is there a way to change the page's title in code behind (C#)?

I want to change this part:
<HEAD>
<TITLE> Can be changed dynamically. </TITLE>
</HEAD>

Thanks,
Guogang


Nov 18 '05 #5
Gerry,

The problem with what you are trying to do is that ASP.NET treats everything
from the first character of the output (usually "<!DOCTYP.. ." for VS.NET
created WebForms) to the first control as a LiteralControl. this means that
the title is within this LiteralControl as literal text to be spit out
(without further processing) at Render-time. This is very efficient, but
puts the title out of reach for the base implementation of
System.Web.UI.P age.

The only sure-fire way to completely control this is by creating a class
that derives from System.Web.UI.P age and then adding private variable and an
accessor for a property named "Title".

Then, override the Render method. In that method, you'll need to find the
<title> control in the text of that first literal control and change what's
between <title> adn </title> to your internal title variable.

You can view the code (and description) here:

http://www.cerkit.com/cerkitBlog/Per...d-c1e62963db9b
Nov 18 '05 #6
Thanks for the info michael, I will incorporate this in my base page.

However, imho, this is still a bug in VS in that it is 'randomly' removing
things from my html.
The runat="server" method works just fine until VS removes it - I haven't
pinned down exactly when it is removed.


"Michael Earls" <me****@hotmail .com> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Gerry,

The problem with what you are trying to do is that ASP.NET treats everything from the first character of the output (usually "<!DOCTYP.. ." for VS.NET
created WebForms) to the first control as a LiteralControl. this means that the title is within this LiteralControl as literal text to be spit out
(without further processing) at Render-time. This is very efficient, but
puts the title out of reach for the base implementation of
System.Web.UI.P age.

The only sure-fire way to completely control this is by creating a class
that derives from System.Web.UI.P age and then adding private variable and an accessor for a property named "Title".

Then, override the Render method. In that method, you'll need to find the
<title> control in the text of that first literal control and change what's between <title> adn </title> to your internal title variable.

You can view the code (and description) here:

http://www.cerkit.com/cerkitBlog/Per...d-c1e62963db9b

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
38326
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the pages using the require_once function. That is, each page includes the line <?require_once('PageStart.php')?>
2
17294
by: Treetop | last post by:
is there a way to change the <title> tag from a parent window from a child window in frames?
2
6155
by: Pete Kipe | last post by:
I'm not a JavaScript programmer...but I'm trying to put together a simple menu system for a new website and need a little help. I have the following script: <SCRIPT language=javascript> <!-- Hide JavaScript from Java-Impaired Browsers function NavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#CC0000";}} function NavRollOut(oTd) {if (!oTd.contains(event.toElement))
4
2653
by: Jake Lewis | last post by:
I have an HTML page that loads fine including the .js file <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script language="JavaScript" type="text/JavaScript" src="ve3d.js" ></script> </head>
14
3473
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... I want to completely seperate the code from presentation. I would like to do the same thing for a value of a hidden form field but
1
6498
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page. I am able to call values from file in my jsp page. But as dynamic values can be any in no...
0
4044
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page.But as dynamic values can be any in no i don't know how could i populate all those in my jsp...
3
4980
by: synergy_711 | last post by:
I feel like this should be fairly easy but I have been struggling with this for sometime. I have not been able to find someone who's had the same problem as mine yet. http://g.bach.home.insightbb.com/movies.html I have a page set up on my website to view videos from various sites by creating html pages and creating links to view them inside an iframe. I'm getting tired of creating pages for every video that I find and it seems to make...
5
5698
by: Simon Benson | last post by:
Probably a fairly simple problem but one that's been plaguing me for a couple of days... can anyone help? I have a classic ASP page with a number of text boxes which are updatable. For convenience I want to add 'tabs' at the top of the page (like a card index) as the data to be displayed is split into specific groups (client, company, preferences, events). How do I update any changes to the data and switch to a different page - at
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.