Avatar of dsmarket
dsmarket asked on

Script for changing the title of a web page dynamically

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>
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
dweppenaar

8/22/2022 - Mon
dweppenaar

So if I understand you correctly you want to change the tile of the page you are currently at, basically overriding the default title you get from the master page. Why not put the name change in the Page Load of the pages implementing the Master Page?
ASKER
dsmarket

where exactly in the page should i put it ?
dweppenaar

In the code behind the page. If you switch to design view and double click the WebForm it should take you to the Page_Load event of the current page. Like in the code snippet.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Change title of the page
            this.Title = "My New Title";
        }
    }
}

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
dsmarket

In Portal.Master i have something similar to what you've mentioned :

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

So should i put it there ? however i still not understand how by using the  following line :
 
"this.Title = "My New Title";
i can give a different title to each page

dweppenaar

If you set the page title in the Master page it basically sets the name for all the pages that use the master page. So if you want to have individual names for each of your pages you must set their names in their own Page_Loads. Thus if you do not specify a name change in the page load of an individual page, it gets the name change from the master page, ie. DEFAULT_PAGE_TITLE. But if you do put some kind of name change in the 'child' pages using the master page, this will override the name which you specified.

I just used "My New Title" as an example and this.Title will give you the same result as Page.Title. You can give it your individual names.

To view the Page_Load of the other pages double click somewhere on the form when you are in design view.

I have attached a screenshot on how to view the code of a aspx page. Remember, view the code of the child pages, not the master page.
Right-Click-and-View-Code.jpg
ASKER
dsmarket

Ok, so this is understood .
but i have also cases where from one default.aspx i have references to several pages
like :default.aspx?ProdID=8,default.aspx?ProdID=9
How can i define also a different title for each PROD id ?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
dweppenaar

In your case I see you use querystrings to pass the product ID from one page to the next.

So in the orinigating page you encode the values, something like so:

string ProdID = Server.UrlEncode(txtProdID.Text);
Response.Redirect("Page2.aspx?ProdID=" & ProdID);

And to decode it at the destination page, something like this:

string ProdID = Request.QueryString("ProdID");
Response.Write("Your Product ID is " + ProdID);

The decoding part will usually be in the Page_Load. Then it is up to you specify the title of the page.

Something like this (in the page load):

string ProdID = Request.QueryString("ProdID");
Page.Title = "Your Product ID is " + ProdID;

This is just an example.

Hope it helps.
ASKER
dsmarket

The relevant default.aspx and the ascx files attached below.
Can you specify exactly where should i locate the snippets you mentioned above ?

default.aspx
<%@ 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>

front.ascx
<%@ Control Language="C#" %>
<%@ Register Assembly="RadMenu.Net2, Version=4.4.2.0, Culture=neutral, PublicKeyToken=bbe59a8ad3533e68"
    Namespace="Telerik.WebControls" TagPrefix="radM" %>
<%@ 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" %>

<table style="border-style: solid; border-width: thin; border-top-color: 788F97; border-right-color: 788F97; border-bottom-color: 788F97; border-left-color: 788F97;"
    width="193px"><tr><td><asp:HyperLink ID="hk_products_backend" runat="server" ImageUrl="~/images/bars/front_end.gif"></asp:HyperLink></td></tr>
<tr><td>
    <radM:RadMenu ID="RadMenu1" runat="server" DataSourceID="SqlDataSource1" Flow="Vertical"
        Skin="Vista" Width="190px"
              DataFieldID="ProdID"
            >
                <DataBindings>
            <radM:RadMenuItemBinding TextField="title"   NavigateUrlField="NavURL" />
           
           
            <radM:RadMenuItemBinding TextField="ProdID" Depth="1" />
        </DataBindings>
    </radM:RadMenu>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:portalDSN %>"
        SelectCommand="SELECT [ProdID]  ,[ProdCatID], [title], [display_order], [full_text], [lang_id] ,'~/products/front/default.aspx?ProdID=' + CAST(ProdID AS char(10)) as NavURL From [Prdocuts] WHERE (([lang_id] = @lang_id) AND ([ProdCatID] = @ProdCatID)) ORDER BY [display_order]">
        <SelectParameters>
            <asp:Parameter DefaultValue="en" Name="lang_id" Type="String" />
            <asp:Parameter DefaultValue="2" Name="ProdCatID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</td></tr>
</table>

dweppenaar

What are you using to develop in? If its Visual Studio .NET there should be another file called: Default.aspx.cs

In this file the code looks like this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "My New Title";
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://www.google.com");
        }
    }
}

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
dsmarket

We didn't developed it and when i login to FTP i'm not able to see *.cs files.
Question is  : can we create these files using Visual Studio .NET ?
dweppenaar

Yes you can. If you create an ASP project you get a .cs file by default each time you add a aspx page to the project. The aspx files are for the user interface layout and design. The .cs files contain the code that is executed behind the scenes.
ASKER
dsmarket

Ok, so now we generated cs file and as you can see down below we inserted a code related to
the decoding part.Is this the right place to insert it  ? now, where should i insert the encoding part ?
In the default.aspx itself ?

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
    public partial class default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          {
           string ProdID = Request.QueryString("ProdID");
           Page.Title = "Your Product ID is " + ProdID;
        }

        }
    }
}
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
dweppenaar

The decoding part is fine inside the Page_Load like below (I just took out the extra brackets). The encoding part you put in the code where you redirect to the new URL. Such as a button on the originating page. For example, if the current page is http://localhost/default.aspx and the destination page is http://localhost/product.aspx then you add your query string variables, so the destination string becomes something like: http://localhost/product.aspx?prodID=123456

If your default page (where you click to go to the product page) has a .cs file, I would create a button and put it in the code of the button click.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
namespace WebApplication1
{
    public partial class default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {          
           string ProdID = Request.QueryString("ProdID");
           Page.Title = "Your Product ID is " + ProdID;
        }
    }
}

Open in new window

ASKER
dsmarket

Just to make sure if i did it right.
Please go to http://www.m-photo.com/products/backend/ to see how the site is built.
In the left side of the page you can see a dynamic menu (which function like buttons). If you stand on one of the item , you can see down below the full address with the PRODID after the question mark.
Now,  please see down below the encoding part that i integrated in the default.aspx file
(I put this snippet within the <SelectParameters> tags )

<%@ Page Language="C#" MasterPageFile="~/App_Masters/Portal.Master" AutoEventWireup="true" Theme="Standard"  Buffer="true" %>
<%@ Register Src="~/App_Controls/Backend.ascx" TagName="Backend" 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="0" />
string ProdID = Server.UrlEncode(txtProdID.Text);
Response.Redirect("default.aspx?ProdID=" & ProdID);
    <asp:Parameter DefaultValue="1" Name="ProdCatID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>  
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="leftPan">
    <uc1:Backend ID="Backend1" runat="server" />
</asp:Content>
dweppenaar

It looks good to me and your querystrings are also fine. Can you extract the querystrings at the destination pages?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
dsmarket

Unfortunately i get a crash

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
ASKER
dsmarket

Hi dweppenaar,
Any clue why i getting the above error ?
Can you check once again the files ?
dweppenaar

Do you have access to the server running the application? If you do you can run it there and see what the error is. If not, can you possible run it on your local machine and see if you get the same error. I went to the URL you gave and it worked fine for me. When do you get the error? When you redirect to a destination page, or what were you doing when it occured?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
dsmarket

Well , i'm not an ASP.NET specialist but when i look at the two lines i added to default.aspx i can see immediately that something in the syntax is wrong.
You can verify it yourself :   the two lines -

string ProdID = Server.UrlEncode(txtProdID.Text);
Response.Redirect("default.aspx?ProdID=" & ProdID);

appear after the closing tag which is :   /> .

Now , as i can see in the file every command should be within starting  tag and closing tag  like :
 <asp:Parameter ..... /> and these lines are NOT.
I'm 100% sure that this is the cause for the error and it can't be run as is. Something in the syntax should be changed.
Please look at it once again and notify me how to write it properly.
dweppenaar

I agree with your statement that this is the cuase for the error. I would put that code inside the button click event of the page wich will be responsible for the redirection. If this is not possible for some reason (the page does not have a code behind .cs file), then you can also possibly use JavaScript to do the redirection. But you cannot place that c# code as it is there in the page source. That code like it is there, needs to be in the code behind part (.cs file) like shown in the code snippet.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string ProdID = Request.QueryString["ProdID"];
            Page.Title = "Your Product ID is " + ProdID;
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
            string ProdID = Server.UrlEncode(txtProdID.Text);
            Response.Redirect("default.aspx?ProdID=" + ProdID);
        }
    }
}

Open in new window

ASKER
dsmarket

Well, to tell you the truth i'm a bit confused. What do you mean by "the code behind .cs file ?"
I attached below the code from the ascx file(this file is being referred from default.aspx)  maybe we can insert here the additional lines instead of
using java script ?

<%@ Control Language="C#" %>
<%@ Register Assembly="RadMenu.Net2, Version=4.4.2.0, Culture=neutral, PublicKeyToken=bbe59a8ad3533e68"
    Namespace="Telerik.WebControls" TagPrefix="radM" %>
<%@ 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" %>

<table style="border-style: solid; border-width: thin; border-top-color: 788F97; border-right-color: 788F97; border-bottom-color: 788F97; border-left-color: 788F97;"
    width="193px"><tr><td><asp:HyperLink ID="hk_products_backend" runat="server" ImageUrl="~/images/bars/front_end.gif"></asp:HyperLink></td></tr>
<tr><td>
    <radM:RadMenu ID="RadMenu1" runat="server" DataSourceID="SqlDataSource1" Flow="Vertical"
        Skin="Vista" Width="190px"
              DataFieldID="ProdID"
            >
                <DataBindings>
            <radM:RadMenuItemBinding TextField="title"   NavigateUrlField="NavURL" />
           
           
            <radM:RadMenuItemBinding TextField="ProdID" Depth="1" />
        </DataBindings>
    </radM:RadMenu>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:portalDSN %>"
        SelectCommand="SELECT [ProdID]  ,[ProdCatID], [title], [display_order], [full_text], [lang_id] ,'~/products/front/default.aspx?ProdID=' + CAST(ProdID AS char(10)) as NavURL From [Prdocuts] WHERE (([lang_id] = @lang_id) AND ([ProdCatID] = @ProdCatID)) ORDER BY [display_order]">
        <SelectParameters>
            <asp:Parameter DefaultValue="en" Name="lang_id" Type="String" />
            <asp:Parameter DefaultValue="2" Name="ProdCatID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
</td></tr>
</table>

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
dweppenaar

I have attached an image of two screenshots. The first view is the source code of an ascx file (or User Web Control), as well as the design view. The second view at the botton is of the code behind file for the same ascx file. All I did was double click the button on my design view and it created the button click event and I placed the code there.

Notice that there is no code inside the ascx source except the code for the user interface controls.
Code-behind-view--.cs-file--of-a.jpg
ASKER
dsmarket

Your example is very good and clear but is not relevant to my situation.
As you saw in our site , we dont use such a button but dynamic menus.
Moreover, redirection works ok and I dont want to touch it. I want only to change the title according ProdID.
As I informed you in one of our earlier correspondence, I already implemented the change of titles in all of  the default.aspx where
There is only one page. So I added to each page something like :
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
 
     this.Title = "Our company";

    }
</script>

And this works fine.
Now I want to change the script in the following manner so if for example prodid is one then the title will be something like : blaa.. blaa.
I wonder if its not possible to write it in the following manner as written below.
The whole issue with redirection is not relevant for me because its already works only the dynamic titles are missing

<script runat="server">
  protected void Page_Load(object sender, System.EventArgs e)
    {

        if (ProdID=1) Page.Title = = product number 1
        {
     
               if (ProdID=2) Page.Title = = product number 2

        }

        {
                   else  Page.Title = product number 3;
        }
    }

 
</script>
dweppenaar

Ah, now I understand. Then it will work fine. You just need to extract the ProdID and your set. I have included a simple if-else in the code snippet which should work.
<script runat="server">
  protected void Page_Load(object sender, System.EventArgs e)
  {
        //Insert code to extract ProdID from querystring here
 
        if (ProdID==1) 
           Page.Title = "Product Number 1";
        else if (ProdID==2)
           Page.Title = "Product Number 2";
        else if (ProdID==3)
           Page.Title = "Product Number 3";
  }
</script>
 
//Alternative using a switch
 
<script runat="server">
  protected void Page_Load(object sender, System.EventArgs e)
  {
        //Insert code to extract ProdID from querystring here
 
        switch(ProdID)
        {
           case 1: 
             Page.Title = "Product Number 1";
           break;
 
           case 2:
             Page.Title = "Product Number 2";
           case 3:
             Page.Title = "Product Number 3";
        }
  }
</script>
 
//Alternative Just Using ProdID
 
<script runat="server">
  protected void Page_Load(object sender, System.EventArgs e)
  {
        //Insert code to extract ProdID from querystring here
 
        Page.Title = "Product Number " + ProdID.ToString();
  }
</script>

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
dweppenaar

Just forgot to add the last two break statements in the second option.
ASKER
dsmarket

I tried each of this option and get a crash , should  i define the ProdID ?
<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>


ASKER CERTIFIED SOLUTION
dweppenaar

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question