473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Page title in ASP.NET pages

Hello
For displaying page titles for my ASP.NET applications I use the following technique
<title><%=BannerModule.PageTitle%></title
where BannerModule.PageTitle 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 2894
Maxim
The page title disappears after a post back probably because you did not assign the BannerModule.PageTitle 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><%=BannerModule.PageTitle%></title
where BannerModule.PageTitle 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.UserControl
{
protected Label Title;

private void Page_Load(object sender, System.EventArgs e)
{
Title.Text = "Hello World";
}

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

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

"Maxim Izbrodin" <mi*******@nospamalias.com> wrote in message news:<2D**********************************@microso ft.com>...
Hello,
For displaying page titles for my ASP.NET applications I use the following technique:
<title><%=BannerModule.PageTitle%></title>
where BannerModule.PageTitle 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.PageTitle %>
</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.Text;
}
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>element 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 HtmlGeneralControl member in the codebehind
page class like:

public class TestTitle : System.Web.UI.Page
{
.......
protected System.Web.UI.HtmlControls.HtmlGenericControl MyTitle;
.............

Then, we can specify the page's title dynamically by change the MyTitle
member's InnerText property, just as:
private void Page_Load(object sender, System.EventArgs e)
{
MyTitle.InnerText = "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(object sender, System.EventArgs e

BannerModule.PageName = ResString.IDS_BANNER_TITLE_LOGIN()
FormsAuthentication.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
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...
6
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
0
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...
82
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...
42
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
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...
21
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...
10
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.