What is probably a simple question about a file control

G

Guest

I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb
question here. I've been searching all over the place for an answer and
haven't found a single one.

I'm working on a form that gives the user a file control to upload a file
from their machine to my server. With this file control are two buttons; one
marked "Upload", the other marked "Cancel". The cancel button is to give
them the option of just backing out entirely. Upon clicking the Cancel
button, the C# code redirects them to the previous page.

The problem I'm having is that if the user has already selected a file on
their computer (through clicking Browse, etc.) and they click "Cancel" the
file is uploaded to the server anyway. How do I prevent the upload if they
click the "Cancel" button and not the "Upload" button.

Thanks in advance,
ed
 
G

Guest

if the only functionality of cancel is to go back to last page , change
cancel button to an HTML button.. it doesnt need to post back the page.

<input type=button onclick='javascript:history.back(-1);' value='Cancel'>

Still how is it uploading file on cancel button?.. :) Is your c# code to
save the file on in the btnUpload_Click(Sender as Object, e as EventArgs)
[btnUpload being name of your uplaod control] or in the Page_Load ?

btnUpload_Click(Sender as Object, e as EventArgs) is the currect place for
saving the file to server..
 
G

Guest

Sreejith,
thanks. Thats exactly what I was looking for.

ed

Sreejith Ram said:
if the only functionality of cancel is to go back to last page , change
cancel button to an HTML button.. it doesnt need to post back the page.

<input type=button onclick='javascript:history.back(-1);' value='Cancel'>

Still how is it uploading file on cancel button?.. :) Is your c# code to
save the file on in the btnUpload_Click(Sender as Object, e as EventArgs)
[btnUpload being name of your uplaod control] or in the Page_Load ?

btnUpload_Click(Sender as Object, e as EventArgs) is the currect place for
saving the file to server..



Ed said:
I'm rather new to ASP .Net, so I appologize in advance if I'm asking a dumb
question here. I've been searching all over the place for an answer and
haven't found a single one.

I'm working on a form that gives the user a file control to upload a file
from their machine to my server. With this file control are two buttons; one
marked "Upload", the other marked "Cancel". The cancel button is to give
them the option of just backing out entirely. Upon clicking the Cancel
button, the C# code redirects them to the previous page.

The problem I'm having is that if the user has already selected a file on
their computer (through clicking Browse, etc.) and they click "Cancel" the
file is uploaded to the server anyway. How do I prevent the upload if they
click the "Cancel" button and not the "Upload" button.

Thanks in advance,
ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top