2

I'm new to this so apologies if it's an easy one:

I have a webpage with an iframe in it, the code in the iframe uploads a file to a folder.

Once the file is uploaded I want to refresh the parent page which list the uploaded files.

This is the code that fires to upload the file:

void Button1_Click(object Source, EventArgs e){
    if (File1.Value == ""){
        Span1.InnerHtml = "Error: you must enter a file name";
        return;
    }
    if (File1.PostedFile != null){
        try{

            File1.PostedFile.SaveAs(Server.MapPath(Request.QueryString["fpath"]+"\\")+File1.Value);


          Span1.InnerHtml = "File Uploaded";            

        }
        catch (Exception exc){
            Span1.InnerHtml = "Error saving file" + File1.Value + "" + exc.ToString();
        }
    }
}

I had hope I could just stick a window.parent.location.href = window.parent.location.href; in after saveas line

  • Take a look at this answer: http://stackoverflow.com/questions/5351342/reload-parent-window-from-within-an-iframe – wicker95 Jun 08 '15 at 15:17

2 Answers2

0

This answer is JS, not C#.

According to this answer, you can use :

window.top.location.reload();

EDIT: Your question is tagged as Javascript, and I thought you were using a framework I did not know, however research makes me think this is C#.

Community
  • 1
  • 1
Moustach
  • 2,904
  • 1
  • 13
  • 23
  • I would say right before `Span1.InnerHtml `but you'll need to somehow send the JS. We might need more details about your problem, but this page could help: http://stackoverflow.com/questions/6368948/asp-net-refresh-base-page-from-iframe – Moustach Jun 08 '15 at 15:20
  • If I add that into my code after: File1.PostedFile.SaveAs(Server.MapPath(Request.QueryString["fpath"]+"\\")+File1.Value); I just get a server error the page wont display – Nathan Fuller Jun 08 '15 at 15:21
0

You could call this function:

window.location.reload()

After uploading.

teoreda
  • 2,392
  • 1
  • 21
  • 28