Document title

T

Tumurbaatar S.

How to change a document's title programmatically, from the Page_Load() for
example?
 
G

Grant Merwitz

you can either create a literal and set its text to:
<Title>Some TITLE</title>

Or, you can declare a public variable in your code like follows
public string PageTitle;

then in your Title tag do this:
<TITLE><%=PageTitle%></TITLE>
 
T

Tumurbaatar S.

Thank you!
There's no a special property/method to manipulate with a document title?
So, only way is to combine ASP.NET script and HTML tags.
I think that <%= PageTitle %> will assign initial value of the variable,
i.e. before
processing it within Page_Load(). May be it will work as I think:

<TITLE><%# PageTitle %></TITLE>
public string PageTitle;
Page_Load()
{
PageTitle = some_expression;
DataBind();
}

Am I right?
 
G

Grant Merwitz

Sounds fine to me, never tested i though.

if you change the # to and =, you wouldn't have to use the Page.DataBind()
method.
But it should work fine
 
S

Siva M

Another option:

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

In the code-behind:

pageTitle.InnerText = "Your page title goes here...";


How to change a document's title programmatically, from the Page_Load() for
example?
 
G

Grant Merwitz

i was also thinking that.

But how do you declare the title in your code behind?
Vis studio doesn't add it automatically
 
S

Siva M

Hi,

Declare it as HtmlGenericControl.


i was also thinking that.

But how do you declare the title in your code behind?
Vis studio doesn't add it automatically
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top