473,714 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page title in ASP.NET pages

Hello
For displaying page titles for my ASP.NET applications I use the following technique
<title><%=Banne rModule.PageTit le%></title
where BannerModule.Pa geTitle is a public field of my user control. This field is initialized in Page_Load of every my page. This technique works with the exception that the title disappears every time a page is posted back. Could somebody explain me the reason, or suggest a better technique for setting page title at run-time?
Thanks a lot
Maxim
Nov 18 '05 #1
5 2912
Maxim
The page title disappears after a post back probably because you did not assign the BannerModule.Pa geTitle on the page post back. You have to assign that value to the control again for it to display properly. Alternatively, you can place placeholder control between the title tags and in your code you populate the title. That way, you don't have to worry about postback problem if you enable viewstate

Tu-Thac

----- Maxim Izbrodin wrote: ----

Hello
For displaying page titles for my ASP.NET applications I use the following technique
<title><%=Banne rModule.PageTit le%></title
where BannerModule.Pa geTitle is a public field of my user control. This field is initialized in Page_Load of every my page. This technique works with the exception that the title disappears every time a page is posted back. Could somebody explain me the reason, or suggest a better technique for setting page title at run-time?
Thanks a lot
Maxim
Nov 18 '05 #2
Are you checking if there is a postback in the Page_Load method.

if (!IsPostBack) {
}
else {
}

You want to make sure that you set this every time.

Also you should create a user control to render out the title of the page.
This will all the pages will have the same title:

<title>
<uc1:Banner id="Banner1" runat="server"> </uc1:Banner>
</title>
public class Banner : System.Web.UI.U serControl
{
protected Label Title;

private void Page_Load(objec t sender, System.EventArg s e)
{
Title.Text = "Hello World";
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
}
http://www.xpcoder.net

"Maxim Izbrodin" <mi*******@nosp amalias.com> wrote in message news:<2D******* *************** ************@mi crosoft.com>...
Hello,
For displaying page titles for my ASP.NET applications I use the following technique:
<title><%=Banne rModule.PageTit le%></title>
where BannerModule.Pa geTitle is a public field of my user control. This field is initialized in Page_Load of every my page. This technique works with the exception that the title disappears every time a page is posted back. Could somebody explain me the reason, or suggest a better technique for setting page title at run-time?
Thanks a lot,
Maxim

Nov 18 '05 #3
Hi Maxim,
Thanks for posting in the community!
From your description, you embed an UserControl into a webpage, the
UserControl has a Public string property so that you can use the value of
this property to set the UserControl's container page's title via such code:
<title>
<%=TitleUC1.Pag eTitle %>
</title>
However, you found that the page's title value will disappear after the
page is posted back.
Also, you're looking for anyother approachs to set the page's title, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my research, as for your first problem, I agree to Tu-Thach and
coder5811's suggestion that you need to set the UserControl's PageTitle
Property not only when the page is first time loaded but also when posted
back. For example, use the below code in UserControl:
if(!IsPostBack)
{
PageTitle = "Initial Title";
}
else
{
//the case when page is posted back
PageTitle = txtPageTitle.Te xt;
}
Thus, the title won't disappear when the page is posted back.

As for any other approachs to set the page's title, I found there is
another means to set the page's title dynamically------------set the
<titile>eleme nt as runat=server and provide an unique id, For example,
specify the titile in page as below:
.........
<HEAD> <TITLE ID="MyTitle" RUNAT="server"> </TITLE> </HEAD>
...........

and also need to declare a HtmlGeneralCont rol member in the codebehind
page class like:

public class TestTitle : System.Web.UI.P age
{
.......
protected System.Web.UI.H tmlControls.Htm lGenericControl MyTitle;
.............

Then, we can specify the page's title dynamically by change the MyTitle
member's InnerText property, just as:
private void Page_Load(objec t sender, System.EventArg s e)
{
MyTitle.InnerTe xt = "My Custom Title!";
}

In addtion, here is weblinks to some tech artiles which have dicussed on
this topic, you may have a view if you feel any thing unclear:

#How to Change the Page Title in ASP.NET dynamically
http://www.dotnetspider.com/Technolo...px?SampleId=12

#Setting the ASP.NET Page Title and Meta Tags
http://authors.aspalliance.com/chris...sp?article=141

Please try out the preceding suggestions. If you have any questions, please
feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Thank you all
I did assigned the text value to the user control member not only when the page was initially displayed, but also when it was posted back
private void Page_Load(objec t sender, System.EventArg s e

BannerModule.Pa geName = ResString.IDS_B ANNER_TITLE_LOG IN()
FormsAuthentica tion.SignOut()

But it works as I described (the title is lost after when the page is posted back). I've tried the method suggested by Steven Cheng (<TITLE ID="MyTitle" RUNAT="server"> </TITLE>) and it works. Thank you, Steven!
Nov 18 '05 #5
Hi Maxim,
Thanks for your prompt response. I'm very glad that my suggestion has
helped you. In addtion, if you meet any other problems or need assitance in
the furture, please always feel free to post here. I'll be willing to assit
you. Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
38336
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the pages using the require_once function. That is, each page includes the line <?require_once('PageStart.php')?>
6
2469
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
0
1382
by: b | last post by:
When I create chm with docbook I have most of the pages on one file. So, when I search for "Linux" page begins with "Sample HTML" .... I get the page with several pages in one. Can this be avoided? Can every page (copyright, disclaimer, credits) be on separate pages? Also when viewing chm "Sample xml" text is in the same page as "introduction", "copyright" ... here is xml: Sample-HOWTO.xml
82
6316
by: Eric Lindsay | last post by:
I have been trying to get a better understanding of simple HTML, but I am finding conflicting information is very common. Not only that, even in what seemed elementary and without any possibility of getting wrong it seems I am on very shaky ground . For example, pretty much every book and web course on html that I have read tells me I must include <html>, <head> and <body> tag pairs. I have always done that, and never questioned it. ...
42
3878
by: smerf | last post by:
Using javascript, is there a way to trap an external page inside a frame? I've seen scripts to break out of frames, but nothing to keep a page trapped in a frame.
13
1945
by: Dan Aldean | last post by:
Hi, I use ASP.NET 2.0 and I created a stylesheet, but I don't know how to make it visible to a web form "MyWebPage.aspx" that uses the master page. I put a reference to the css in the .master but it's not visible to the newly created page. MyWebPage.aspx doesn't have a <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head>structure.
21
7688
by: karen987 | last post by:
I have a news website, with asp pages. It has publishing software which allows you to add articles in a database, and then calls them up from links etc. I have added dynamic meta tags in 2 parts. The first part is in the inc.header.asp file which is called up on every page. The page itself has the meta tag variable, ie. title, description. They work fine on all pages, except the one below i'm having problems with. Ironically it's the most...
10
10437
Ajm113
by: Ajm113 | last post by:
Making a History Page for BIG Sites Intro: Ok, let's say after a while your website has grown massive. We're talking search engine, forum and video hosting -- you've got a LOT of content. And you are wondering, "Why do I need yet another feature for my big site?" Well, some people can become forgetful every time they see content on your site, and let's suppose that one day they needed to work on a good php script for their class and they...
1
3460
by: epower | last post by:
Hello, I am working on an ASP .NET application in Visual Studio 2005 and running IE7. This application has a page that contains an iframe which loads an .aspx page and hyperlinks that load the iframe with different .aspx pages. The HTML/mark up for the .aspx pages executes every time, but the Page_Load events for the pages never run (on initial load or subsequent loads).
0
8808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9316
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2525
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.