ASP.NET代码表达式,数据绑定和其他声明式Expressoins [英] ASP.NET Code Expression, Data Binding, and other Declarative Expressoins

查看:122
本文介绍了ASP.NET代码表达式,数据绑定和其他声明式Expressoins的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些标签有什么区别?



<%
<%#
<%=
< ;%$



更重要的是,如何在ASP.NET控件中使用声明式语法显示页面属性?我试图在ASP.NET控件中这样做。任务是设置标签的文本,但是我不希望在我想要更改输出控件的情况下进行此工作。我收到一个关于服务器端控件的错误,不能包含这个语法。我不知道我需要一个数据控制来控制我想做什么,但这是另一个选择。



部分答案来了。



更新
有一个我在ASP.NET 4.5中看到的新标签?网站



<%:

解决方案

部分回答


从Mike Banavige引用


<%%>嵌入式代码块为
服务器代码在
页面的渲染阶段执行。
块中的代码可以在
当前页面类中执行编程
语句和调用函数。
http://msdn2.microsoft.com /en-gb/library/ms178135(vs.80).aspx



<%=%>最有用的显示
单件的信息。
http://msdn2.microsoft.com /en-us/library/6dwsdcf5(VS.71).aspx



<%#%数据绑定表达式语法。
http://msdn2.microsoft.com/en-us/ library / bda9bbfx.aspx



<%$%> ASP.NET表达式。
http://msdn2.microsoft.com/en-us/ library / d5bd1tad.aspx



<%@%>指令语法。
http://msdn2.microsoft.com /en-us/library/xz702w3e(VS.80).aspx



<% - - %>服务器端注释。
http://msdn2.microsoft.com/en-US/图书馆/ 4acf8afk.aspx


更新:



这似乎工作

 < asp:Label ID =MyLabelrunat =serverText ='<%# MyProperty%>'>< / asp:Label> 

如果我使用eval语法,那么我收到一个关于数据绑定控件的错误,或者我使用<%那么我得到一个服务器端控件错误。任何更多的颜色赞赏..不知道我真的明白发生了什么。



也许它与渲染阶段有关。



几个更多的观察:



我可以使用<%=没有数据绑定并获取属性值,但不能在服务器端控件没有得到错误。



如果我在服务器端控件中使用<%#,但需要执行Page.Databind。



有趣的是,当我想要渲染不在控件内的文本时,我可以使用<%=或<%#。虽然后者需要数据绑定。



解释了新的<%:语法,也称为代码表达式语法


使用ASP.NET 4,我们引入了一个新的代码表达式语法(<%:
%>),使得输出像<%=%>块才能实现 - 但是还有
自动HTML编码,然后再执行此操作。


http://weblogs.asp。 net / scottgu / new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2


What are the differences in these tags?

<% <%# <%= <%$

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.

Partial answer coming up.

Update There is a new tag I've seen in ASP.NET 4.5? site

<%:

解决方案

Partial answer

quoted from Mike Banavige

<% %> An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx

<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx

<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx

<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx

Update:

Okay this appears to work

<asp:Label ID="MyLabel" runat="server" Text='<%# MyProperty%>'></asp:Label>

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.

Perhaps it has something to do with the render phase.

Few more observations:

I can use <%= without databinding and get the property value but can not use it in a server side control without getting error.

If I use <%# in server side control but I'm required to do a Page.Databind.

Interestingly, I can use either <%= or <%# when I want to render text that is not inside a control. Although the latter requires databinding.

The new <%: syntax is explained, also called code expression syntax

With ASP.NET 4 we are introducing a new code expression syntax (<%: %>) that renders output like <%= %> blocks do – but which also automatically HTML encodes it before doing so.

http://weblogs.asp.net/scottgu/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2

这篇关于ASP.NET代码表达式,数据绑定和其他声明式Expressoins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆