This definitely works, I use the same concept in my applications. So we need to track down where the break is occurring. How are you developing this thing? In Visual Studio? Can you verify that after you put runat="server" in the title element that you
can access it's InnerHtml property from code-behind? Are you sure you are setting it equal to a real value and not an empty string or something?
"Dream as if you'll live forever, live as if you'll die today." --James Dean
Ok, so you are using Master Pages. I assume the Master Page is the part that has the title element, yes? Which Page_Load are you setting the .InnerHtml property from, the Master page's Page_Load or a specific page?
"Dream as if you'll live forever, live as if you'll die today." --James Dean
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SiteMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
titleElement.InnerHtml = newsTitle;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Details : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
titleElement.InnerHtml = newsTitle;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class SiteMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
titleElement.InnerHtml = newsTitle;
}
}
Asos
0 Points
22 Posts
News Title in title bar
Jan 04, 2013 08:54 PM|LINK
Hello,
I have been searching for finding how to get the title of news in the title bar but couldn't find any solution.
I have a table named "News" fields of the table is ( NewsID, NewsTitle, NewsDetails, NewsDate)
now I want the feild "NewsTtitle" became the title of the page.
any idea please!
AceCorban
Star
12318 Points
2269 Posts
Re: News Title in title bar
Jan 04, 2013 09:00 PM|LINK
make your title element runat="server"
<head> <title id="titleElement" runat="server"></title> </head>Then in your Page_Load, where you extract the news data, you just set the .InnerHtml property of the titleElement tag:
Asos
0 Points
22 Posts
Re: News Title in title bar
Jan 04, 2013 09:18 PM|LINK
Hello AceCorban
I did the way you toldme but didn't work.
AceCorban
Star
12318 Points
2269 Posts
Re: News Title in title bar
Jan 04, 2013 09:34 PM|LINK
This definitely works, I use the same concept in my applications. So we need to track down where the break is occurring. How are you developing this thing? In Visual Studio? Can you verify that after you put runat="server" in the title element that you can access it's InnerHtml property from code-behind? Are you sure you are setting it equal to a real value and not an empty string or something?
Asos
0 Points
22 Posts
Re: News Title in title bar
Jan 04, 2013 09:42 PM|LINK
I use Visual web developer 2010
i didn't get any error but i still get the static title from the master page. not the title from the "NewsTitle" record.
AceCorban
Star
12318 Points
2269 Posts
Re: News Title in title bar
Jan 04, 2013 09:53 PM|LINK
Ok, so you are using Master Pages. I assume the Master Page is the part that has the title element, yes? Which Page_Load are you setting the .InnerHtml property from, the Master page's Page_Load or a specific page?
Asos
0 Points
22 Posts
Re: News Title in title bar
Jan 04, 2013 10:05 PM|LINK
that is the master page
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class SiteMasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { titleElement.InnerHtml = newsTitle; } }using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Details : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { titleElement.InnerHtml = newsTitle; } }Asos
0 Points
22 Posts
Re: News Title in title bar
Jan 04, 2013 10:08 PM|LINK
yes
i set it in "MasterPage.master.cs"
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class SiteMasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { titleElement.InnerHtml = newsTitle; } }AceCorban
Star
12318 Points
2269 Posts
Re: News Title in title bar
Jan 04, 2013 10:28 PM|LINK
Have you verified that in this instance the newsTitle variable holds the appropriate String? Mind if I see the relevant head section of your .Master?
Asos
0 Points
22 Posts
Re: News Title in title bar
Jan 04, 2013 10:34 PM|LINK
thanks for the answers again
that is the head of my master page