I haven't come to the csdn blog for a long time. TodayCommunityI can see a question about "<% # %>" in Asp.net, so I still wantArticlePost it to your blog. Although it is not a very profound problem, you should pay more attention to it ......
AspxPage,<% = %>And<% # %>Difference
Most of ASP. NET Some of them are mentioned in the textbooks. <% = %> And <% # %> The difference is that the binding time is different, <% # %> Is called in the control Databind Function. For <% = %> I think you should be familiar ASP Times, it is equivalent Response. Write . In ASP. NET The same is true of the times. For the moment, ignore what is mentioned in the textbook and put the "binding time" aside. <% = %> And <% # %> The difference is: the former is the output, and the latter is the value assignment! That is:
<% = "A" %>Equivalent:Response. Write ("");
<% # "A" %>Equivalent to: Variable= "";
Let's look at an example:
<Html>
<Body>
<ASP: button Text=<%# "Hello, the Internet! " %> Runat= "Server"ID= "Testbutton"/>
</Body>
</Html>
This sentence is equivalent to a value assignment. Translate the above blacklisted sentence into the background.CodeThat is:Testbutton. Text = "hello, the Internet! ";
Example 2:
<Html>
<Body>
<%= "Hello, the Internet! "%>
<%# "Hello, the Internet! "%>
</Body>
</Html>
<% = "Hello, the Internet! "%>It is equivalent:Response. Write ("hello, the Internet! ");
Then the second<% # %>How can this problem be explained? If, according to my "assignment", who does it assign the value?
In fact, the translated background code is as follows:(New system. Web. UI. literalcontrol (). Text = "hello, the Internet! ";
A piece of text. Although it is not included between any start and end labels[Font = 'courier] ASP. NET [/font]It is also considered as a control. One[Font = 'courier] literalcontrol [/font]Control. So,[Font = 'courier] <% # %> [/font]Is to assign the value[Font = 'courier] literalcontrol [/font]ControlTextAttribute.
I used a class to generate static HTML code. The htmltextwriter class is encapsulated. And I did tracking debugging. I was surprised by the tracking results. ASP. NET regards all the tags that are not marked with the "runat = server" attribute as a literalcontrol control. For example, in the preceding HTML code, for example, in the HTML code at the beginning of the article, ASP. NET considers that there are three server controls: literalcontrol, button, and literalctontrol. The text value of the first literalcontrol is " hello, theinternet !", The text value of the last literalcontrol is " ". That is to say, <% = %> should be translated before <% # %> ......