Code for dynamically changing the webpage title in asp.net
Source: Internet
Author: User
Method 1.
First, on the. aspx page:
<HEAD>
<Title>
<% = PageTitle %>
</Title>
.......
</HEAD>
Second, on 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 webpage as the "title" of the displayed page content"
PageTitle = lblBiaoTi. Text;
...
Note: Here, lblBiaoTi is a Label control, TextBox Control, or other server control.
PageTitle = lblBiaoTi. Text; before a sentence, the Text attribute of lblBiaoTi must be assigned a value.
Method 2: Use the Literal control
First, drag a Literal control to the. aspx page. Set the ID to PageTitle.
Second, go to the. aspx HTML page, cut and paste the code of the newly added Literal control into the <title> and </title>.
Finally, set the PageTitle value in the appropriate position on the. aspx. cs page, for example, 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
{
............
// 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 webpage as the "title" of the displayed page content"
PageTitle = lblBiaoTi. Text;
...
Note: Here, lblBiaoTi is a Label control, TextBox Control, or other server control.
PageTitle = lblBiaoTi. Text; before a sentence, the Text attribute of lblBiaoTi must be assigned a value.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service