在ASP.NET中,有哪些不同的方式来内联code在.aspx?内联、不同、方式、有哪些

2023-09-04 00:04:02 作者:时间让爱笑的女孩哭了

我可以得到一个'时,使用'这些和其他人呢?

Can I get a 'when to use' for these and others?

<% %>
<%# EVAL() %>

感谢

推荐答案

检查出的 Web窗体语法参考的MSDN上。

Check out the Web Forms Syntax Reference on MSDN.

有关基本知识,

&LT;%%>用于纯code块。我一般只用这个if语句

<% %> is used for pure code blocks. I generally only use this for if statements

&LT;%,如果(IsLoggedIn){%>     &NBSP; &LT; D​​IV CLASS =认证>     &LT;%}其他{%>     &NBSP; &LT; D​​IV CLASS =未>     &LT;%}%>

<% if (IsLoggedIn) { %> <div class="authenticated"> <% } else { %> <div class="unauthenticated"> <% } %>

&LT;%=前pression%>用于添加文本到您的标记;也就是说,它相当于到&lt;%的Response.Write(出pression)%>

FPGA工程师用了都喜欢的编辑神器 Vs Code

<%= Expression %> is used to add text into your markup; that is, it equates to <% Response.Write(Expression) %>

&LT; D​​IV CLASS ='&LT;%= IsLoggedIn? 认证:未%>>

<div class='<%= IsLoggedIn ? "authenticated" : "unauthenticated" %>'>

&所述;%实施例#pression%>非常类似于上述情况,但它是在数据绑定方案进行评估。有一件事,这意味着你可以使用这些EX pressions来设置=服务器的控制,你不能在&lt做价值;%=%>语法。通常情况下,这是用于数据绑定控件的模板内,但你也可以用它在你的页面,然后调用的Page.DataBind()(或Control.DataBind())引起的code来评价。

<%# Expression %> is very similar to the above, but it is evaluated in a DataBinding scenario. One thing that this means is that you can use these expressions to set values of runat="server" controls, which you can't do with the <%= %> syntax. Typically this is used inside of a template for a databound control, but you can also use it in your page, and then call Page.DataBind() (or Control.DataBind()) to cause that code to evaluate.

在链接的文章中提到的人是不太常见,但是肯定有其用途了。

The others mentioned in the linked article are less common, though certainly have their uses, too.