Change Page Title (ASPX 2.0)

Discussion in 'ASP .Net' started by Christian Ista, Mar 9, 2006.

  1. 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,
     
    Christian Ista, Mar 9, 2006
    #1
    1. Advertising

  2. Christian Ista

    Jacob Guest

    Try this.Title =
    ConfigurationManager.AppSetting["WebSiteName"].toString();
     
    Jacob, Mar 9, 2006
    #2
    1. Advertising

  3. 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.



    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ===================================
    "Christian Ista" <> wrote in message
    news:...
    > 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,
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Juan T. Llibre, Mar 9, 2006
    #3

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


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

    Thanks,
     
    Christian Ista, Mar 9, 2006
    #4
  5. You're making this harder than it needs to be.
    Just use code like this:

    Page.Title = "Whatever"

    --
    I hope this helps,
    Steve C. Orr
    MCSD, MVP
    http://SteveOrr.net



    "Christian Ista" wrote:

    > 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,
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=, Mar 9, 2006
    #5
  6. 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.
     
    Erik Funkenbusch, Mar 10, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    499
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    580
  3. Replies:
    1
    Views:
    597
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,852
    soonic
    Jul 27, 2011
  5. Russell
    Replies:
    2
    Views:
    329
    Russell
    Sep 13, 2004
Loading...

Share This Page