0

ページの読み込み時に URL がバインドされていない背景画像を持つ div があります。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;">

デバッガーに入り、プロパティにブレークポイントを設定しましたが、サイトはプロパティを呼び出しません。

4

2 に答える 2

1

get-set の使用方法は次のとおりです。

private string _headlineimg ="N/A";
public property HeadlineBackgroundImagePath() As string{
    get{
        return _headlineimg
   }
    set{
        _headlineimg = value
    }
}

次に、ページ読み込みイベント:

HeadlineBackgroundImagePath = "whatever";
于 2013-06-24T17:01:11.547 に答える
0

アニの答えは私を正しい道に導きましたが、解決策の一部に過ぎませんでした. 提案どおりにプロパティを設定しましたが、コード ビハインドで画像パスを設定した後に 1 行のコードを追加する必要がありました。ページ読み込みイベントでプロパティを設定し、Page.DataBind() を呼び出して機能させました。

    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
        {
        }
    }
于 2013-06-24T18:45:18.833 に答える