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  
 http://www.m-photo.com  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 : http://www.m-photo.com/products/backend/
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
http://www.m-photo.com/products/backend/default.aspx?ProdID=9   (title 1)
http://www.m-photo.com/products/backend/default.aspx?ProdID=10 (title 2)
Etc&

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;
        }
    }



   
</script>

This is the code of one of the default.aspx (in this case it is the http://www.m-photo.com/products/backend/)


<%@ 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">
                             <ItemTemplate>                                
                             <h2><%# DataBinder.Eval(Container.DataItem, "title")%></h2>
                              <%# DataBinder.Eval(Container.DataItem, "full_text")%>
                             </ItemTemplate>
                         </asp:Repeater><asp:SqlDataSource id="dsGeneral" runat="server" ConnectionString="<%$ ConnectionStrings:portalDSN %>" SelectCommand="sp_get_ProductsByID" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:QueryStringParameter Name="ProdID" QueryStringField="ProdID"
        Type="Int32" DefaultValue="1" />
    <asp:Parameter DefaultValue="2" Name="ProdCatID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>          
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="leftPan">
    <uc1:front ID="front1" runat="server" />
</asp:Content>
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