I'm building a tiny blog app, and what I need to do is show blog post title for dynamically generated content page Item.aspx in page title.
In other words, i need data that is bound to this label in FormView to also be shown in page title when page loads.
<asp:Label ID="lblPostTitle" runat="server" Text='<%# Eval("PostTitle") %>' />
I'm using ObjectDataSource to get the data.
Tried a bunch of things, tried this (http://goo.gl/zWz1) to access Eval in code behind, but nothing worked.
Edit:
OK, i got the value from returned DataTable, it's easy
protected void odsItem_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
DataTable dt = (DataTable)e.ReturnValue;
string postTitle = dt.Rows[0]["PostTitle"].ToString();
}
But when I pass it to Page.Title nothing happens.
Please help.
Thank you.
Ok, i found the problem. Earlier, I added this code to Master page code-behind.
protected override void Render(HtmlTextWriter writer)
{
Page.Title = "Site name" + Page.Title;
base.Render(writer);
}
Once I commented it out, i was able to pass dynamic page title value to Page.Title.
This code worked great for appending the page title when content page Title was read from aspx file, but now i have to find another way to append the title.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.