我有一个带有背景图片的div,当页面加载时,url没有被绑定。 URL在后面的代码中的get方法中设置。不知道我在这里做错了什么。
HTML:
<div class="decorator" style="background: transparent url(<%# HeadlineBackgroundImagePath %>) top center no-repeat; height: <%# HeadlineBackgroundImageHeight %>px;">
背后的代码:
protected string HeadlineBackgroundImagePath
{
get
{
return ($CompanyContext.Entity as IPPCUpdateEntity).HeadlineBackground.ShortSrc;
}
}
protected int? HeadlineBackgroundImageHeight
{
get
{
return ($CompanyContext.Entity as IPPCUpdateEntity).HeadlineBackground.Height;
}
}
当页面加载时,我得到类似的内容(注意URL中没有任何内容):
<div class="decorator" style="background: transparent url() top center no-repeat; height: px;">
我已进入调试器,在属性上设置断点,但该站点甚至没有调用该属性。
答案 0 :(得分:1)
这就是你使用get-set的方式:
private string _headlineimg ="N/A";
public property HeadlineBackgroundImagePath() As string{
get{
return _headlineimg
}
set{
_headlineimg = value
}
}
然后在页面加载事件:
HeadlineBackgroundImagePath = "whatever";
答案 1 :(得分:0)
protected void Page_Load(object sender, EventArgs e)
{
try
{
HeadlineBackgroundImagePath = ($CompanyContext.Entity as IPPCUpdateEntity).HeadlineBackground.ShortSrc;
Page.DataBind();
if (!String.IsNullOrEmpty(($CompanyContext.Entity as IPPCUpdateEntity).FloodlightTag))
floodlightTag.Text = ($CompanyContext.Entity as IPPCUpdateEntity).FloodlightTag;
}
catch
{
}
}