Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileUpload control resending

Status
Not open for further replies.

Denster

Programmer
Apr 9, 2001
198
0
0
GB
Does anyone know how to avoid this problem using the file upload control. Everything works fine and uploads as it should, however if a link is clicked to navigate away from the page then click the back button on the browser I get a page expired and a retry message box. If I click OK the file gets uploaded again. I've tried this on a blank page and it does the same so theres nothing else to interfere with it. Anybody else had the same issue?
 
This is related to how webforms processes requests. a common pattern used to process posting data is post-redirect-get. user submits form using post. after changing the data the request redirects to another url. this url will render the html for display. This avoids the "resubmit" confirmation.

Webforms doesn't follow this model. when a form is submitted the same request is used to get the html results. by clicking the back button webforms wants to submit the request.

I don't know if there is a work around for this in webforms.


Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
To get round this I thought it might be a good idea to popup a separate window with the javascript function - window.open(). This all works fine but to close it I use the self.close function, how on earth can I refresh the original page to show the file I've just uploaded. This is causing me so much hassle, there has to be a way round this problem!
 
popups are not a good idea. most browsers will prevent them anyway. there is an option, either or a button control or form (i don't remember) that allows a webform to submit to a different page. you could try using this to solve the problem.



another option is to not use webforms. I'm a big advocate for MVC so I would recommend this route. It's a paradigm shift from the web development experience webforms offers, but i find it's a better model for building web applications.



Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
popups are not a good idea. most browsers will prevent them anyway. there is an option, either or a button control or form (i don't remember) that allows a webform to submit to a different page. you could try using this to solve the problem.

There is a follow TTer, Mark (c8sam) who has a mastery knowledge of webforms. Mark, if you're reading this, do you have any insight into this scenario?

another option is to not use webforms. I'm a big advocate for MVC so I would recommend this route. It's a paradigm shift from the web development experience webforms offers, but i find it's a better model for building web applications.



Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
You have a few options that I can think of:

1. Use a javascript based file upload

2. Set the PostBackUrl property of your submit button to post the data to another page.

3. Prevent the page being cached - I'm not sure on how this will perform cross browser though so you would need to test it.

I'd probably go with #1 or #2.


Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Denster said:
...This all works fine but to close it I use the self.close function, how on earth can I refresh the original page to show the file I've just uploaded. ...

1. Place a LinkButton on your "original" page (that calls the event in step 2)
2. Create a server side event on the "original" page that refreshes the control that lists your uploaded files

3. On the page thats opened via window.open(), process your uploads, and at the end, write out a javascript function to close itself and refresh the opening page. (I've done this with a slight delay so a message appears ("File Uploaded Successfully"))

Code:
protected void DoSomething(object sender, EventArgs e)
{
    try 
    {
        MyFileSystem.UploadFiles();
        StatusMessage.Text = "It Worked";
        LabelOnBottomOfPage.Text = "<script language='javascript'>closeAndRefresh();</script>";
    }
    catch (Exception ex)
    {
        Log(ex);
    }
}

Javascript - i just dropped this into the head tags of the "pop up" window, and hard coded the reference to the link of the "original" page
Code:
<script type="text/javascript">
    function closeAndRefresh() {
        setTimeout(ExitPopUp, 1500);
    }
    function ExitPopUp() {
        window.opener.document.getElementById("ctl00_ContentPlaceHolder1_lbRefresh").click();
        window.close();
    }
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top