I am using an iframe to upload an image. So I have two files - the file for the iframe and the file that will display the image. When the link to display the iframe is clicked this code is run:

function ShowUploadImageOut(RecordID) {
        $('#<%=hfPieceID.ClientID %>').val(RecordID);
        $("#dvAddImageOutturn").html("<iframe id=\"iframeUpload\" src='utilities/UploadPOD.aspx?id=uploadOutturn'></iframe>");

On the iframe is an upload button that saves the image to a folder on the computer and sets the image file name to FileNameHidden

protected void btnUpload_Click(object sender, EventArgs e)
            if (fuUpload.HasFile)
                 if (Request.QueryString["id"] == "uploadOutturn")
                        String Path = ConfigurationManager.AppSettings["PieceOutturnFolder"].ToString() + Company.Current.CompCode;
                        string FileName = fuUpload.FileName;

                        if (File.Exists(Path + "/" + FileName))
                            File.Delete(Path + "/" + FileName);
                        fuUpload.SaveAs(Path + "/" + FileName);
                        filename = FileName;
                        imgTemp.ImageUrl = "/thumbnail.ashx?ImgFilePath=" + Path.Replace("/", "\\") + "\\" + FileName + @"&width=200&height=400";
                        FileNameHidden.Value = FileName;

FileNameHidden has the property clientidmode to static:

Back on the page for displaying the image there is a save button. This button takes the value from FileNameHidden and sets it to a hidden field. This new hidden field is used to save the file name to the database:

 <asp:HiddenField ID="hfUploadedPieceHubImageFile" runat="server" />

<div id="dvAddEditImageOutturn"  class="dvdraggable">   
     <div id="dvAddImageOutturn">
     <asp:LinkButton ID="btnPieceHubUpdateImage" onclick="btnUpdatePieceImage_Click" OnClientClick="CloseUploadWindow();return GetPieceOutturnFilename();" CssClass="btnSaveSmall" runat="server" ></asp:LinkButton>

function GetPieceOutturnFilename() {
        if ($('#iframeUpload').contents().find('#FileNameHidden').length > 0) {
            $("#<%= hfUploadedPieceHubImageFile.ClientID %>").val(($('#iframeUpload').contents().find('#FileNameHidden').val()));
       return true;

The problem is in the GetPieceOutturnfile function. $('#iframeUpload').contents().find('#FileNameHidden').length is always zero. It should be finding the FileNameHidden from the iframe.

Going through the code I can see FileNameHidden definitely gets set the name of the image:

<input name="FileNameHidden" type="hidden" id="FileNameHidden" style="display:none" value="test.jpg">

So I don't understand why it says the length is zero

Related posts

Recent Viewed