Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2005

Tip: Looking for answers? Try searching our database.

Chenge WEB page title

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Val - 30 Sep 2005 15:58 GMT
How do i programmatically change a title of a Web page in ASP.NET?

Thanks
Mark White - 30 Sep 2005 16:15 GMT
Val

<title><%if(Condition){Response.Write("Title A");}else{Response.Write("Title
B");}%></title>

Mark

> How do i programmatically change a title of a Web page in ASP.NET?
>
> Thanks
Tom Spink - 30 Sep 2005 16:55 GMT
> Val
>
[quoted text clipped - 6 lines]
>>
>> Thanks

We could actually streamline this a bit:

///
<title><%=(condition) ? "Title A" : "Title B" %></title>
///

Signature

Tom Spink

Val - 30 Sep 2005 17:04 GMT
That does not work from CodeBehind file (aspx.cs)! Is there an
object/property that I can change to change title?

Thanks

> Val
>
[quoted text clipped - 6 lines]
> >
> > Thanks
Mark White - 30 Sep 2005 17:11 GMT
Ok, what you can do is have a protected string as a member var. of the
code-behind.
protected string sTitle = "";

In Page_Load or wherever you want, throw the logic in it to determine the
value of your title string.
if(Condition)
{
   sTitle = "Title A";
}
else
{
   sTitle = "Title B";
}

In the front-end .aspx page:
<title><%=sTitle%></title>

Mark

> That does not work from CodeBehind file (aspx.cs)! Is there an
> object/property that I can change to change title?
[quoted text clipped - 11 lines]
> > >
> > > Thanks
carion1 - 30 Sep 2005 18:59 GMT
In the html file add:

<title id="myTitle" runat="server" />

In the code behind add a field:

protected System.Web.UI.HtmlControls.HtmlGenericControl myTitle;

In page_load add:

myTitle.InnerText = "Hello World";

You can adapt it however you wish from there.

Signature

Derek Davis
ddavis76@gmail.com

> That does not work from CodeBehind file (aspx.cs)! Is there an
> object/property that I can change to change title?
[quoted text clipped - 12 lines]
>> >
>> > Thanks
clintonG - 30 Sep 2005 19:44 GMT
VS2003 mangles the HTML title element when moving between the designer and
code behind so all of those other comments have been proven risky and a PITA
to use. Thus, the better strategy is to use a Literal control in the <head>
element

// .aspx
<head><asp:Literal id="pageTitle" /></head>

// .cs
pageTitle.Text = "Home Page";

<%= Clinton Gallagher
        METROmilwaukee (sm) "A Regional Information Service"
        NET csgallagher AT metromilwaukee.com
        URL http://metromilwaukee.com/
        URL http://clintongallagher.metromilwaukee.com/

> How do i programmatically change a title of a Web page in ASP.NET?
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.