最近<%=
、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"; }
}
Page_Load:
TheTitle = TheContentItem.Title;
TheBody = TheContentItem.Body;
ページ上:
<div id='<%= ContentID %>'>
<h2 class='title'><%= TheTitle ?? "No Title" %></h2>
<p><%= TheBody %></p>
</div>