ASP.NET通过隐藏代码设置页面标题 [英] ASP.NET Set Page Title from Code Behind
本文介绍了ASP.NET通过隐藏代码设置页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用ASP.NET C#创建数据驱动的页面,并希望使用后面的代码动态设置页面标题
I am creating data driven pages using ASP.NET C# and want to dynamically set the page title using code behind
<%@ Page Title="" Language="C#" MasterPageFile="~/FLMaster.master" AutoEventWireup="true" CodeFile="legal-expenses-insurance-news-item.aspx.cs" Inherits="legal_expenses_insurance_news_legal_expenses_insurance_news_item" %>
我尝试使用页面下方的单独标题标签,但这也不起作用.任何人都可以建议如何做到这一点.
I have tried using the separate title tags lower down in the page but this didn't work either. Can anyone advise how to do this.
推荐答案
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyApplication
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "Title of my page";
}
}
}
您可以从 aspx.cs (文件后面的代码)中修改上述页面标题.
You can modify the Page title like above from your aspx.cs (the code behind file).
如果要直接在 .aspx 文件中执行此操作,请尝试以下操作:
If you want to do this directly in your .aspx file, try this:
<% this.Title = "Some Title" %>
如果您在 @Page
指令中正确设置了 Language ="C#"
,则此方法有效,我认为您已经做到了.
This works if you correctly set your Language = "C#"
in your @Page
directive, which I see you did.
这篇关于ASP.NET通过隐藏代码设置页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文