Change Page Title (ASPX 2.0)

C

Christian Ista

Hello,

I have a problem to change title page at runtime.

In the page ASPX :
<title runat="server" id="pageTitle"></title>

In code behind :
public partial class _Default : System.Web.UI.Page

In the Page_Load:
pageTitle.InnerText = ConfigurationManager.AppSettings["WebSiteName"];

But I receive this error :
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific error
details and modify your source code appropriately.

Compiler Error Message: CS0102: The type '_Default' already contains a
definition for 'pageTitle'

When I replace pageTitle.InnerText but a textbox no problem.

Any idea ?

Thanks,
 
J

Juan T. Llibre

It looks like you are missing the declaration :

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

Declare the control and
pageTitle.InnerText = ConfigurationManager.AppSettings["WebSiteName"];

will start working.
 
C

Christian Ista

Try this.Title =
ConfigurationManager.AppSetting["WebSiteName"].toString();

This work fine : pageTitle.Text =
ConfigurationManager.AppSettings["WebSiteName"];

Thanks,
 
G

Guest

You're making this harder than it needs to be.
Just use code like this:

Page.Title = "Whatever"
 
E

Erik Funkenbusch

On Thu, 9 Mar 2006 17:51:15 +0100, Christian Ista wrote:

Every page exposes a Title property that will change the title without
having to specify a runat=server title element. Just set Title="My new
title" or whatever in your code behind.
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top