2

I want to set image.imageurl dinamically... But the code bellow just works when the page is not on a masterpage.

Here is the code:

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);
}
1
  • do you have an UpdatePanel on the MasterPage? Commented Feb 28, 2013 at 10:04

2 Answers 2

1

In the MasterPage the Id is derived from the ContentPlaceHolder, e.g.:

ctl00$ContentPlaceHolder1$Image1

But why don't you simply use Image1.ClientId instead?

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img",
    "top.document.getElementById('" + Image1.ClientId + "').src='data:image/jpg;base64," + base64String + "';",
    true);
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

No problem! would you mind upvoting my answer and possibly mark it as answered? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.