什么时候应该在 ASP.NET 控件中使用 # 和 =? [英] When should I use # and = in ASP.NET controls?

查看:26
本文介绍了什么时候应该在 ASP.NET 控件中使用 # 和 =?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 ASP.NET 多年,但我永远不记得何时使用 # 和 = 合适.

I have been using ASP.NET for years, but I can never remember when using the # and = are appropriate.

例如:

<%= Grid.ClientID %>

<%# Eval("FullName")%>

有人可以解释一下什么时候应该使用每一个,这样我就可以牢记在心吗?# 是否仅用于支持数据绑定的控件?

Can someone explain when each should be used so I can keep it straight in my mind? Is # only used in controls that support databinding?

推荐答案

<%= %> 相当于在任何地方执行 Response.Write("").

<%= %> is the equivalent of doing Response.Write("") wherever you place it.

<%# %> 用于数据绑定,只能在支持数据绑定的情况下使用(如果您在代码隐藏中调用 Page.DataBind(),则可以在控件外的页面级别使用这些)

<%# %> is for Databinding and can only be used where databinding is supported (you can use these on the page-level outside a control if you call Page.DataBind() in your codebehind)

数据绑定表达式概述

这篇关于什么时候应该在 ASP.NET 控件中使用 # 和 =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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