问题描述
什么是这些标签的区别在哪里?
What are the differences in these tags?
<%
<%#
&所述;%=
<%$
<%<%#<%=<%$
更重要的是,我怎么显示ASP.NET控件使用声明语法的页面的属性?我试图做到这一点在ASP.NET控件。任务是设置一个标签的文本,但我不想这样做有利于在语法我想改变输出控件的事件。我得到一个错误有关服务器端控件不能包含此语法。我不知道,我需要为我想做的事,但是,什么是另一种选择数据绑定控件。
More importantly, how do I display a page property using declarative syntax in an ASP.NET control? I'm trying to do this in an ASP.NET control. The task is to set the text of a label but I do not want to do this pro grammatically in the event I want to change the output control. I get an error about server side controls can't contain this syntax. I'm not sure that I need a databound control for what I want to do but that is another option.
部分答案来了。
更新
有我在ASP.NET 4.5见过的新标签?网站
UpdateThere is a new tag I've seen in ASP.NET 4.5? site
&LT;%:
推荐答案
部分答案
从迈克Banavige报价
quoted from Mike Banavige
&LT;%%>嵌入code块
服务器code,它在执行
页面的呈现阶段。在code在
块可执行程序
语句和通话功能的
当前页面类。
&LT;%=%>显示最有用
单条信息。
<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
&LT;%#%>数据绑定防爆pression语法。
<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx
&LT;%$%> ASP.NET防爆pression。
<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx
&LT;%@%>指令语法。
<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx
&LT;% - - %>服务器端注释。
<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx
更新:
好吧,这似乎工作
<asp:Label ID="MyLabel" runat="server" Text='<%# MyProperty%>'></asp:Label>
如果我使用eval语法然后我得到有关数据绑定控件错误或我使用的&lt;%然后,我得到了一个服务器端控件错误。任何更多的颜色AP preciated ..不知道我真正明白是怎么回事。
If I use the eval syntax then I get an error about databound control or I use the <% then I get a server side controls error. Any more color appreciated.. not sure I really understand what is going on.
也许它是与呈现阶段。
很少有更多的意见:
我可以使用&lt;%=无数据绑定和获得属性值,但在服务器端控制,而得到错误不能使用它
I can use <%= without databinding and get the property value but can not use it in a server side control without getting error.
如果我使用&lt;%#在服务器端控制,但我必须做的Page.DataBind
If I use <%# in server side control but I'm required to do a Page.Databind.
有趣的是,我可以使用&LT;%=或LT。虽然后者需要数据绑定。
Interestingly, I can use either <%= or <%# when I want to render text that is not inside a control. Although the latter requires databinding.
新&LT;%:语法解释,也被称为code EX pression语法
The new <%: syntax is explained, also called code expression syntax
使用ASP.NET 4我们引入了一个新的code EX pression语法(小于%:
%呈现输出像>)LT;%=%>块做 - 但也
自动HTML恩codeS它才这样做的。
http://weblogs.asp.net/scottgu/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2
这篇关于ASP.NET code防爆pression,数据绑定和其他声明前pressoins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!