0

Code is working great. The preview after picking image using asyncfileupload appears. But once I place the page into an iframe, it doesn't work anymore. I think the problem is that once it is place into the iframe, this script : top.$get(\"" + ImagePreview.ClientID + "\") can't really find my ImagePreview.

I tried using document.getElementById("<%= ImagePreview.ClientID %>") but no success.

protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    if (AsyncFileUpload1.HasFile)
    {
        Session["AsyncFileUpload1"] = AsyncFileUpload1;
        this.Session["AsyncFileUploadBytes"] = AsyncFileUpload1.FileBytes;
        Random random = new Random();
        int num = random.Next(10);
        string savePath = MapPath("~/Images/Temp/Preview" + num + ".jpg");
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + AsyncFileUpload1.ClientID + "\").innerHTML = 'Uploaded size: " + AsyncFileUpload1.FileBytes.Length.ToString() + "';", true);
        AsyncFileUpload1.SaveAs(savePath);
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "image", "top.$get(\"" + ImagePreview.ClientID + "\").src = '../../../Images/Temp/Preview" + num + ".jpg'", true);
    }
}
CSDev
  • 3,177
  • 6
  • 19
  • 37
  • Your question says `ImagePreview.ClientID` but the code says `Image.ClientID`. Is one a typo? – wazz Jul 27 '19 at 02:12
  • Yup, I am sorry. I did change that to avoid confusion of image control to actual image. I edited my post, thank you. – John Robert Jul 27 '19 at 04:09

0 Answers0