Question

Script for changing the title of a web page dynamically

Asked by: dsmarket

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>

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-05-21 at 08:58:16ID23421409
Tags

c#, asp.net

Topics

Programming for ASP.NET

,

Microsoft Visual C#.Net

Participating Experts
1
Points
260
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. asp.net custom controls and changing dynamically the pag…
    hi there, i am very good in asp 3.0 and starting to learn c# and asp.net i heard that its better to replace the include statements with user controls... what i am trying to do is the following: (please advise me if i am wrong) i have a portal composed of a header, body , a...
  2. runat=server line disappears
    I have a webform on which the title is changed dynamically. For that purpose I added runat="server" to the <title> tag: <title id="pageTitle" runat="server">My Title</title> the problem is that somehow runat="server"...
  3. ASP.NET Dynamic Page Title, Runat=Server is disapering
    Hello, i have an aspx page, in the title of it i use: <TITLE ID=PageTitle RUNAT=server></TITLE> so i can go in the behind code and enter: Protected PageTitle As New HtmlGenericControl and in the page_load i use: Me.PageTitle.InnerText = "Hello World&quo...
  4. change browser title dynamically
    hi expert, how can i change browser title in code, i knew one way is to set the <title runat=server id="pagetitle"> and then i can access the control in code. any other way i can change the title without specify the title id and runat attribute at aspx page. ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: dweppenaarPosted on 2008-05-21 at 09:17:00ID: 21616572

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?

 

by: dsmarketPosted on 2008-05-21 at 11:35:49ID: 21617719

where exactly in the page should i put it ?

 

by: dweppenaarPosted on 2008-05-21 at 11:47:02ID: 21617837

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

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:

Select allOpen in new window

 

by: dsmarketPosted on 2008-05-21 at 23:35:06ID: 21621410

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

 

by: dweppenaarPosted on 2008-05-22 at 00:24:20ID: 21621557

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.

 

by: dsmarketPosted on 2008-05-22 at 00:54:24ID: 21621664

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 ?

 

by: dweppenaarPosted on 2008-05-22 at 01:15:58ID: 21621754

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.

 

by: dsmarketPosted on 2008-05-22 at 01:48:13ID: 21621854

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>

 

by: dweppenaarPosted on 2008-05-22 at 02:21:34ID: 21622020

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

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

Select allOpen in new window

 

by: dsmarketPosted on 2008-05-25 at 06:56:36ID: 21642728

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 ?

 

by: dweppenaarPosted on 2008-05-25 at 15:00:08ID: 21643764

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.

 

by: dsmarketPosted on 2008-05-25 at 23:47:31ID: 21644988

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

        }
    }
}

 

by: dweppenaarPosted on 2008-05-26 at 02:04:12ID: 21645400

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;
        }
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

 

by: dsmarketPosted on 2008-05-26 at 23:23:05ID: 21649718

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>

 

by: dweppenaarPosted on 2008-05-27 at 01:44:41ID: 21650310

It looks good to me and your querystrings are also fine. Can you extract the querystrings at the destination pages?

 

by: dsmarketPosted on 2008-05-27 at 02:37:00ID: 21650513

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>

 

by: dsmarketPosted on 2008-05-27 at 23:00:45ID: 21658002

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

 

by: dweppenaarPosted on 2008-05-28 at 02:51:28ID: 21658932

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?

 

by: dsmarketPosted on 2008-05-28 at 06:59:55ID: 21660438

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.

 

by: dweppenaarPosted on 2008-05-28 at 16:17:06ID: 21665093

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

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:

Select allOpen in new window

 

by: dsmarketPosted on 2008-05-29 at 00:33:10ID: 21667006

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>

 

by: dweppenaarPosted on 2008-05-29 at 01:03:58ID: 21667156

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.

 

by: dsmarketPosted on 2008-05-29 at 03:45:43ID: 21667780

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>

 

by: dweppenaarPosted on 2008-05-29 at 10:44:53ID: 21671486

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>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:

Select allOpen in new window

 

by: dweppenaarPosted on 2008-05-29 at 10:45:30ID: 21671492

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

 

by: dsmarketPosted on 2008-06-01 at 01:57:24ID: 21686414

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>


 

by: dweppenaarPosted on 2008-06-01 at 03:05:00ID: 21686486

Did you remember to add the code to actually extract the ProdID?

Notice my comment (//Insert code to extract ProdID from querystring here) in the code where you need to insert the code for querystring extraction like explained in the previous comments.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...