troubleshooting Question

Script for changing the title of a web page dynamically

Avatar of dsmarket
dsmarket asked on
.NET ProgrammingASP.NET
27 Comments1 Solution2294 ViewsLast Modified:
We have a web site built in C# / ASP.NET
Currently we have one title that applies for all pages so if you navigate to each of the pages of  you can verify that the title remains the same.
We want a script that will change the title dynamically so if for example I navigate to :
And I press on each of the products located in the left menu I will get a page with a different title according to the ID
For example   (title 1) (title 2)

This is the code of our Portal. Master page (the main template)

<%@ Master Language="C#" AutoEventWireup="true" %>
<%@ Import namespace="System" %>
<%@ Import namespace="System.Text" %>
<%@ Import namespace="System.Configuration" %>
<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="System.Web" %>
<%@ Import namespace="System.Web.Security" %>
<%@ Import namespace="System.Web.UI" %>
<%@ Import namespace="System.Web.UI.WebControls" %>
<%@ Import namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import namespace="System.Web.UI.HtmlControls" %>
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<%@ Register src="~/App_Controls/support.ascx" tagname="support" tagprefix="uc1" %>
<%@ Register src="~/App_Controls/TopMenu.ascx" tagname="TopMenu" tagprefix="uc2" %>
<%@ Register src="~/App_Controls/News.ascx" tagname="News" tagprefix="uc3" %>
<%@ Register src="~/App_Controls/footer.ascx" tagname="footer" tagprefix="uc4" %>
<%@ Register src="~/App_Controls/copyright.ascx" tagname="copyright" tagprefix="uc5" %>
<script runat="server">
    //Constants defining title for "unnamed" page and
    const string DEFAULT_UNNAMED_PAGE_TITLE = "Untitled Page";
    const string DEFAULT_PAGE_TITLE = "M-Photo Ltd. - Color correction tools for professional photolabs";

    protected void Page_Load(object sender, System.EventArgs e)
        //Set the page's title, if needed
        if (string.IsNullOrEmpty(Page.Title) || Page.Title == DEFAULT_UNNAMED_PAGE_TITLE)
                Page.Title = DEFAULT_PAGE_TITLE;


This is the code of one of the default.aspx (in this case it is the

<%@ Page Language="C#" MasterPageFile="~/App_Masters/Portal.Master" AutoEventWireup="true" Theme="Standard"  Buffer="true" %>
<%@ Register Src="~/App_Controls/front.ascx" TagName="front" TagPrefix="uc1" %>
<asp:Content ID="Content1" runat="server" contentplaceholderid="midPan">
<asp:Repeater id="Repeater1" runat="server" DataSourceID="dsGeneral">
                             <h2><%# DataBinder.Eval(Container.DataItem, "title")%></h2>
                              <%# DataBinder.Eval(Container.DataItem, "full_text")%>
                         </asp:Repeater><asp:SqlDataSource id="dsGeneral" runat="server" ConnectionString="<%$ ConnectionStrings:portalDSN %>" SelectCommand="sp_get_ProductsByID" SelectCommandType="StoredProcedure">
    <asp:QueryStringParameter Name="ProdID" QueryStringField="ProdID"
        Type="Int32" DefaultValue="1" />
    <asp:Parameter DefaultValue="2" Name="ProdCatID" Type="Int32" />
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="leftPan">
    <uc1:front ID="front1" runat="server" />
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 27 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 27 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros