[英]What is difference between <%=%> and <%#%>
All, As for the inline expression in asp.net ,I had some questions about them. 全部,至于asp.net中的内联表达式,我对它们有一些疑问。
By the way, I found below code the first one doesn't works , but second one works. 顺便说一下,我发现下面的代码第一个不起作用,但第二个起作用。 Why?
为什么?
<head runat="server">
<title></title>
<script src="<%#FullyQualifiedApplicationPath%>Scripts/jquery.js" type="text/javascript"></script>
</head><!--Not OK-->
<head runat="server">
<title></title>
<script src="<%=FullyQualifiedApplicationPath%>Scripts/jquery.js" type="text/javascript"></script>
</head><!--OK-->
FullyQualifiedApplicationPath
is a variable defined in code behind. FullyQualifiedApplicationPath
是在代码后面定义的变量。 Thanks your review. 谢谢你的评论。
<%= %> is for loading variables <%# %> is for databaind <%=%>用于加载变量<%#%>用于数据库
Consult this post or this question for more info 有关详细信息,请参阅此帖或此问题
<%#%> is used to bind some data or control by using BIND(read and write purpose) or EVAL(for readonly purpose). <%#%>用于通过使用BIND(读写目的)或EVAL(用于只读目的)来绑定某些数据或控件。
Where as <%=%> is used to display the value of a session in a html page. 其中<%=%>用于在html页面中显示会话的值。
For example when u w3ant to bind data to a grid we use the following syntax 例如,当您想要将数据绑定到网格时,我们使用以下语法
<ItemTemplate>
<asp:Label ID="lbl_Id" Text='<%# Bind("Id") %>' runat="server"></asp:Label>
</ItemTemplate>
The above syntax is used to bind the data in the gridview 上述语法用于绑定gridview中的数据
while the <%=%> You will be able to do c# coding in default. 而<%=%>你可以在默认情况下进行c#编码。 aspx page as well, here is the sample code.
aspx页面也是,这里是示例代码。
To show some output on the page and do some coding over out there
<%=Session["value"].ToString() %>
It will load the session value in the default page. 它将在默认页面中加载会话值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.