The code in asp.net that dynamically changes the title of a web page

  • 2020-05-12 02:28:34
  • OfStack

Method 1.
First: on page.aspx:
< HEAD >
< title >
< %=PageTitle % >
< /title >
.
< /HEAD >
Second: on page.aspx.cs:
public class news_view : System.Web.UI.Page
{
.
// is 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 page title as the "title" of the display page
PageTitle=lblBiaoTi.Text;
.
Note: lblBiaoTi here is an Label control, which can also be an TextBox control or another server control.
PageTitle = lblBiaoTi. Text; The Text attribute 1 of lblBiaoTi must have been assigned before the sentence.
Method 2: use the Literal control
First: drag an Literal control into the.aspx page. ID is set to PageTitle.
Second: go to the HTML page of.aspx and completely cut and paste the code of the newly added Literal control into it < title > and < /title > In between.
Finally: set the value of PageTitle in the appropriate place on the.aspx.cs page, as in 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
{
.
// is 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 page title as the "title" of the display page
PageTitle=lblBiaoTi.Text;
.
Note: lblBiaoTi here is an Label control. It can also be an TextBox control or another server control.
PageTitle = lblBiaoTi. Text; The Text attribute 1 of lblBiaoTi must be assigned before the sentence.

Related articles: