There are two methods for successful experiments:
Method 1.
First: on the .aspx page:
<HEAD>
<title>
<%=PageTitle %>
</title>
. . . . . . .
</HEAD>
Secondly: In the .aspx.cs page:
public class news_view : System.Web.UI.Page
{
. . . . . . . . . . . .
//Used to dynamically set the page title
protected string PageTitle;
. . . .
private void Page_Load(object sender, System.EventArgs e)
{
. . . . . . .
//Dynamically set the title of the web page to the "title" of the displayed page content
PageTitle=lblBiaoTi.Text;
. . .
Note: lblBiaoTi here is a Label control, or it can be a TextBox control or other server control.
PageTitle=lblBiaoTi.Text; The Text attribute of lblBiaoTi must be assigned a value before the sentence.
Method 2: Use Literal control
First: drag a Literal control into the .aspx page. ID is set to PageTitle.
Secondly: Enter the .aspx HTML page, completely cut and paste the code of the Literal control you just added between <title> and </title>.
Finally: Set the value of PageTitle in the appropriate location of the .aspx.cs page, such as the PageLoad function.
Example:
In .aspx:
<Head>
<title>
<asp:Literal id="PageTitle" runat="server"></asp:Literal>
</title>
In .aspx.cs:
public class news_view : System .Web.UI.Page
{
. . . . . . . . . . . .
//Used to dynamically set the page title
protected string PageTitle;
. . . .
private void Page_Load(object sender, System.EventArgs e)
{
. . . . . . .
//Dynamically set the title of the web page to the "title" of the displayed page content
PageTitle=lblBiaoTi.Text;
. . .
Note: lblBiaoTi here is a Label control, or it can be a TextBox control or other server control.
PageTitle=lblBiaoTi.Text; The Text attribute of lblBiaoTi must be assigned a value before the sentence.