从博客文章标题动态设置内容 Page.Title

发布于 2024-09-25 23:46:51 字数 666 浏览 0 评论 0原文

我正在构建一个小型博客应用程序,我需要做的是在页面标题中显示动态生成的内容页面 Item.aspx 的博客文章标题。

换句话说,我需要在页面加载时在 FormView 中绑定到此标签的数据也显示在页面标题中。

<asp:Label ID="lblPostTitle" runat="server" Text='<%# Eval("PostTitle") %>' />

我正在使用 ObjectDataSource 来获取数据。

尝试了很多事情,尝试使用这个(http://goo.gl/zWz1)在代码后面访问Eval,但没有任何效果。

编辑:

好的,我从返回的 DataTable 中获取了值,这很容易

protected void odsItem_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
    DataTable dt = (DataTable)e.ReturnValue;
    string postTitle = dt.Rows[0]["PostTitle"].ToString();
}

但是当我将其传递给 Page.Title 时没有任何反应。

请帮忙。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

快乐很简单 2024-10-02 23:46:51

好的,我发现了问题。早些时候,我将此代码添加到母版页代码隐藏中。

protected override void Render(HtmlTextWriter writer)
{
    Page.Title = "Site name" + Page.Title;
    base.Render(writer);
}

一旦我将其注释掉,我就能够将动态页面标题值传递给 Page.Title。

当从 aspx 文件读取内容页面标题时,此代码非常适合附加页面标题,但现在我必须找到另一种附加标题的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文