Chenge WEB page title

  • Thread starter Thread starter Guest
  • Start date Start date
Val

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

Mark
 
Val

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

Mark

We could actually streamline this a bit:

///
<title><%=(condition) ? "Title A" : "Title B" %></title>
///
 
That does not work from CodeBehind file (aspx.cs)! Is there an
object/property that I can change to change title?

Thanks
 
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
 
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.
 
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/
 
Back
Top