Set foreground tag content and attributes dynamically in the background

Source: Internet
Author: User
Unlike asp, in asp.net, to completely separate code, we generally do not use the <% = %> embedded tag to set some attributes and content.
Generally, there are two situations:
(1) set the tag content, for example, <title> here </title>
(2) set the tag attributes, for example, <body bgcolor = here>
(3) dynamically load some scripts
Let's take a look at (1) and (2 ):
Front-end
<Title id = "mytitle" runat = "server"> </title>
<Body id = "mybody" runat = "server">
Background
Protected HtmlGenericControl mytitle;
Protected HtmlGenericControl mybody;
This. mytitle. InnerText = "test ";
This. mybody. Attributes ["bgcolor"] = "# cccccc ";
Three points are described here:
(1) front-end label runat = server is required
(2) the namespace of HtmlGenericControl is System. Web. UI. HtmlControls.
(3). InnerText and. InnerHtml are different.
For example:
Front-end
<Span runat = "server" id = "myspan"> </span>
Background
This. myspan. InnerText = "<B> test </B>"
The result is:
<Span id = "myspan"> & lt; B & gt; test & lt;/B & gt; </span>
Change background
This. myspan. InnerHtml = "<B> test </B>"
The result is:
<Span id = "myspan"> <B> test </B> </span>
Let's take a look at loading some scripts dynamically.
Generally, there are three situations.
(1) place <asp: Literal Runat = "server"> </asp: Literal> at the front end
(2) output in the background through RegisterStartupScript and RegisterClientScriptBlock
(3) Response. Write output
Example:
(1)
Front-end
<Asp: Literal ID = "myLiteral" Runat = "server"> </asp: Literal>
Background
This. myLiteral. Text + = "<script> alert ('test'); </script> ";
View the source code to see the original
<Asp: Literal ID = "myLiteral" Runat = "server"> </asp: Literal>
Location changed
<Script> alert ('test'); </script>
(2)
To better understand the differences between the two, the foreground is as follows:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

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.