最近我开始<%=
在我的 Web 控件中更频繁地使用。通常我会在代码后面设置字符串属性,然后将它们吐出到表单上。
这是一个坏主意吗?
例如。
代码背后:
特性:
public string TheTitle { get; set; }
public string TheBody { get; set; }
public ContentItem TheContent { get; set; }
public string ContentId {
get
{ return "content" + (TheContent != null) ? TheContent.Id.ToSTring() : "0"; }
}
页面加载:
TheTitle = TheContentItem.Title;
TheBody = TheContentItem.Body;
在页面上:
<div id='<%= ContentID %>'>
<h2 class='title'><%= TheTitle ?? "No Title" %></h2>
<p><%= TheBody %></p>
</div>