2

image.imageurl を動的に設定したい...しかし、次のコードは、ページがマスターページにない場合にのみ機能します。

コードは次のとおりです。

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    Byte[] bytes = AsyncFileUpload1.FileBytes;
    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);

    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img",
        "top.document.getElementById('Image1').src='data:image/jpg;base64," + base64String + "';",
        true);
}
4

2 に答える 2

1

MasterPageで、Idから派生しますContentPlaceHolder。例:

ctl00$ContentPlaceHolder1$Image1

Image1.ClientIdしかし、代わりに単に使用してみませんか?

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img",
    "top.document.getElementById('" + Image1.ClientId + "').src='data:image/jpg;base64," + base64String + "';",
    true);
于 2013-02-28T09:33:32.817 に答える
0

Tim Schmelter is correct, you could also set the ClientIDMode on the control to Static. E.g.

<asp:Image runat="server" ID="Image1" ClientIDMode="Static" />

MSDN Docs: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

于 2013-02-28T12:08:57.027 に答える