function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JasonGablerJasonGabler 

After file upload, return to the current page... but to a specific anchor?

 

I've been successfully uploading files, but unless I setRedirect(true) on my upload function's returned PageReferece,  the PageReference does not get honored.  Ultimately I'd like to come back to the same page, without redirecting (so, keeping form data intact)  and include an anchor upon returning to the page so as to end up at a given spot in the page.  Otherwise, with my upload sub-form in the middle of the page, when I return after the upload my browser confusingly  ends up at the top of the page.  Any ideas?  Here's what I've been trying...

 

 

My sippet of VF:

 

 

 

 

  <div id="upload" class="upload">
    <table><tr>
      <td><apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/></td>  
      <td><apex:commandButton value="Upload Attachment" action="{!uploadFile}"  styleClass="upload-button"/></td>
    </tr></table>
  </div>              

 

 

 

 

 

Snipper of Apex from the controller:

 

 

 

  public PageReference uploadFile(String fileName, Blob fileBody) {
     if(fileBody != null && fileName != null) {  
      Attachment myAttachment  = new Attachment();  
      myAttachment.Body = fileBody;  
      myAttachment.Name = fileName;
      ....
    }   
    PageReference pr = ApexPages.currentPage();
    pr.setAnchor('someplace');
    return pr;
  }

 

jason

Alok_NagarroAlok_Nagarro

Hi Jason,

 

Why don't you try reRender functionality of visualforce ?

Pls do that. It'll work nicely.

 

Thanks,

JasonGablerJasonGabler

Unfortunately this doesn't work... you cannot upload a file with Ajax, so I have learned.  Well, you cannot do it directly.  You have to create a form and target it to a hidden iframe to make the file actually upload.  One issues, is that this already exists between <apex:form> tags, and you may not nest them.  Maybe I'll try a regular HTML <form> ... this is on the back burner for now.  Thanks for trying, though.

 

jason

gv007gv007

Jason,

             try this.

1.After uploading docs display some based on uploading conditional is success or failure

1.then provide a done button to user in that use pagereference function In page page ref redirect where you want to go